Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>C# did not support exception filters like VB does until C# 6. As for how they work, see Eric Lippert's <a href="http://blogs.msdn.com/b/ericlippert/archive/2004/09/01/224064.aspx" rel="nofollow">"Finally" Does Not Mean "Immediately"</a></p> <p>Starting in C# 6, exception filters are supported, as <a href="https://blogs.msdn.microsoft.com/csharpfaq/2014/11/20/new-features-in-c-6/" rel="nofollow">the C# FAQ demonstrates</a>:</p> <pre><code>try { … } catch (MyException e) when (myfilter(e)) { … } </code></pre> <blockquote> <p>If the parenthesized expression after ‘if’ [now <code>when</code>] evaluates to true, the catch block is run, otherwise the exception keeps going.</p> <p>Exception filters are preferable to catching and rethrowing because they leave the stack unharmed. If the exception later causes the stack to be dumped, you can see where it originally came from, rather than just the last place it was rethrown.</p> <p>It is also a common and accepted form of “abuse” to use exception filters for side effects; e.g. logging. They can inspect an exception “flying by” without intercepting its course. In those cases, the filter will often be a call to a false-returning helper function which executes the side effects:</p> </blockquote> <pre><code>private static bool Log(Exception e) { /* log it */ ; return false; } … try { … } catch (Exception e) when (Log(e)) {} </code></pre> <p>Thanks to <a href="https://stackoverflow.com/users/5962841/mafii">Mafii</a> for the link to the C# 6 documentation.</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. 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