2

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; } 

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

2 Comments

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.
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).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.