c# - Exception handling in .NET vs Java -


this question has answer here:

i'm porting library wrote java .net c# , i'm dealing differences in exception handling between 2 worlds.

in particular have abstract class use base class implement several services. in class have these methods:

public void myconcretemethod(){      //...     try {         initialize();     } catch(initializationexception ex){         // ...     }      // ...  }  public abstract void initialize() throws initializationexception; 

every extending class must implement way initialize , know need handle possible initializationexception.

in c# converted code this:

public void myconcretemethod(){      //...      initialize();      // ...  }  public abstract void initialize(); 

but way haven't clear information possible initialization problems: in classes throw exception, , in others not.

so should hanlde them in myconcretemethod? exception shold catch? generic exception?

the difference java has checked exceptions, c# doesn't.

since code porting written in java , assuming had correct exception handling (a matter should language agnostic), catch exceptions in c# code @ same place java code catches them.


in absence of signature-level exception clauses, standard .net practice communicating possible exceptions user of api document them. can document them in assembly documentation , in web documentation (if applicable).


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -