Best Practice for Exception Handling

Is there any performance issue or something else that avoids propagation, or is it better to write it like

try 
{

}
catch
{
throw;
}

      

+2


a source to share


2 answers


Unless you are going to handle the exception, it is best to have nothing other than what you suggest. All it does is add the overhead to the trap and then repeat the same exception.



If you can handle this exception, then don't propagate it further down the call stack.

+3


a source


The only time I can think of when I have such empty catch \ rethrow logic is when I want to log an exception somehow, otherwise I would just let it propagate.



EDIT: Added blank word blank

+1


a source







All Articles