Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Are you catching exceptions that you want to then filter more carefully, so you can then change your mind, decide not to handle them and so rethrow them?</p> <p>If you want to be really careful about this, that's not really a good idea. It's better to never catch the exception in the first place. The reason is that a given <code>try/catch</code> handler should not take the decision to run nested <code>finally</code> blocks for exceptions that it is not expecting to see. For example, if there is a <code>NullReferenceException</code>, it's probably a very bad idea to continue executing any code as it will probably cause another such exception to be thrown. And <code>finally</code> blocks are just code, like any other code. As soon as an exception is caught for the first time, any <code>finally</code> blocks on the stack beneath the <code>try/catch</code> will be executed, by which time it's too late - another exception may be generated, and this means that the original exception is lost.</p> <p>This implies (in C#) that you have to careful write out a separate <code>catch</code> handler for all the exception types you want to catch. It also implies that you can only filter by exception type. This is sometimes very hard advice to follow.</p> <p>It should be possible to filter exceptions in other ways, but in C# it is not. However, it is possible in VB.NET, and the BCL itself takes advantage of this by having a small amount of code written in VB.NET so it can filter exceptions in a more convenient way.</p> <p><a href="https://web.archive.org/web/20091218171254/http://blogs.msdn.com/clrteam/archive/2009/02/05/catch-rethrow-and-filters-why-you-should-care.aspx" rel="nofollow noreferrer">Here's a detailed explanation, with a VB.NET code sample, from the CLR team blog.</a></p> <p><a href="http://incrediblejourneysintotheknown.blogspot.com/2009/02/fatal-exceptions-and-why-vbnet-has.html" rel="nofollow noreferrer">And here's my two cents.</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload