title: What is the advantage of using Exception filters and when should I use them?
body: <p>Comparing the old way versus the new way of error handling, by using Exception filters, what is exactly the advantage for me of using filters and when should I use it? is there an scenario where I can get a good advantage of this new feature?</p>
  
  <p>I have read about the unwinding stack but still I don't get the scenario where we can not handle that under the old way. Explain like I'm 5 please.</p>
  
  <pre><code>try
  {
      Foo.DoSomethingThatMightFail(null);
  }
  catch (MyException ex) when (ex.Code == 42)
  {
      Console.WriteLine("Error 42 occurred");
  }
  </code></pre>
  
  <p>vs</p>
  
  <pre><code>try
  {
      Foo.DoSomethingThatMightFail(null);
  }
  catch (MyException ex)
  {
      if (ex.Code == 42)
          Console.WriteLine("Error 42 occurred");
      else
          throw;
  }
  </code></pre>
  
  <p>I know there is other version of this question, the problem is, that the question mention benefits that I cant actually find, for instance.</p>
  
  <blockquote>
    <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>
  </blockquote>
  
  <p>after doing some testing, I did not see the difference between both, I still see the exception from the place it was <strong>rethrown</strong>. So, or the information is not confirmed, I don't understand the Exception filters( that is why I am asking), or I am doing it wrong (also please correct me if I am wrong).</p>
  
  <pre><code>class specialException : Exception
  {
     public DateTime sentDateTime { get; } = DateTime.Now;
     public int code { get; } = 0;
     public string emailsToAlert { get; } = "email@domain.com";
  }
  </code></pre>
  
  <p>then:</p>
  
  <pre><code>try
  {
     throw new specialException();
     //throw new Exception("Weird exception");
     //int a = Int32.Parse("fail");
  }
  catch (specialException e) when(e.code == 0)
          {
              WriteLine("E.code 0");
              throw;
              //throw e;
          }
  catch (FormatException e) 
          {
              if (cond1)
              {
                  WriteLine("cond1 " + e.GetBaseException().Message+" - "+e.StackTrace);
                  throw;
              }
              throw;
          }
  catch (Exception e) //when (cond2)
          {
              Console.WriteLine("cond2! " + e.Message);
              throw;
          }
  </code></pre>