Thursday, August 30, 2007

Re-throwing exceptions

When you want to pass your catched exception to higher level of exception-handling mechanism don't do something like


catch(Exception e){
Trace.WriteLine("{Message}");
throw new Exception("{Message}", e);
}


instead of this use the following construct, which will pass your exception to higher level:


catch(Exception e){
Trace.WriteLine("{Message}");
throw;
}

1 comment:

Unknown said...

try{..}
catch(exception up){
tracer.blabla();
throw up; //haha
}