views:

95

answers:

2

Hi

Is there any performance problem or something else about letting the exception to propagate, or it is better to write it like this

try 
{

}
catch
{
throw;
}
+3  A: 

If you're not going to handle the exception it's better to have nothing rather than what you propose. All that does is add the overhead of catching and then rethrowing the same exception.

If you can handle the exception do so, but then don't propagate it further up the call stack.

ChrisF
A: 

The only time I can think of when I'd have that kind of empty catch\rethrow logic is when I'd want to log the exception in some way, otherwise I'd just let it propagate.

EDIT: added the missing word empty

ho1
Also, you might want to throw another exception, with the original exception as the inner exception, or do some clean up (like closing a connection) before throwing or rethrowing the exception.
lasseeskildsen
Yep, I missed the word "empty", as in it's not changing the program flow etc (though I'd normally try to put the cleanup in the finally rather than the catch).
ho1