Do try/catch blocks hurt performance when exceptions are not thrown?

During a code review with a Microsoft employee we came across a large section of code inside a try{} block. She and an IT representative suggested this can have effects on performance of the code. In fact, they suggested most of the code should be outside of try/catch blocks, and that only important sections should be checked. The Microsoft employee added and said an upcoming white paper warns against incorrect try/catch blocks.

I’ve looked around and found it can affect optimizations, but it seems to only apply when a variable is shared between scopes.

I’m not asking about maintainability of the code, or even handling the right exceptions (the code in question needs re-factoring, no doubt). I’m also not referring to using exceptions for flow control, this is clearly wrong in most cases. Those are important issues (some are more important), but not the focus here.

How do try/catch blocks affect performance when exceptions are not thrown?

13 Answers
13

Leave a Comment