title: Why are try blocks expensive?
body: <p>I've heard the advice that you should avoid try catch blocks if possible since they're expensive.</p>
  <p>My question is specifically about the .NET platform: Why are try blocks expensive?</p>
  <p><strong>Summary of Responses:</strong></p>
  <p>There are clearly two camps on this issue: those that say that try blocks are expensive, and those that say &quot;maybe a tiny little bit&quot;.</p>
  <p>Those that say try blocks are expensive normally mention the &quot;high cost&quot; of unwinding the call stack. Personally, I'm not convinced by that argument - specially after reading about how exceptions handlers are stored <a href="http://www.yoda.arachsys.com/csharp/exceptions2.html" rel="nofollow noreferrer">here</a>.</p>
  <p>Jon Skeet sits on the &quot;maybe a tiny little bit&quot; camp, and has written two articles on exceptions and performance which you can find <a href="https://jonskeet.uk/csharp/exceptions2.html" rel="nofollow noreferrer">here</a>.</p>
  <p>There was one article that I found extremely interesting: it talked about &quot;other&quot; performance implications of try blocks (not necessarily memory or cpu consumption). Peter Ritchie mentions that he found that code inside try blocks is not optimized as it'd otherwise be by the compiler. You can read about his findings <a href="http://msmvps.com/blogs/peterritchie/archive/2007/06/22/performance-implications-of-try-catch-finally.aspx" rel="nofollow noreferrer">here</a>.</p>
  <p>Finally, there's a blog entry about the issue from the man that implemented exceptions in the CLR. Go take a look at Chris Brumme's article <a href="https://cbrumme.dev/the-exception-model" rel="nofollow noreferrer">here</a>.</p>