title: Catching exceptions with "catch, when"
body: <p>I came across this new feature in C# which allows a catch handler to execute when a specific condition is met.</p>
  
  <pre><code>int i = 0;
  try
  {
      throw new ArgumentNullException(nameof(i));
  }
  catch (ArgumentNullException e)
  when (i == 1)
  {
      Console.WriteLine("Caught Argument Null Exception");
  }
  </code></pre>
  
  <p>I am trying to understand when this may ever be useful.</p>
  
  <p>One scenario could be something like this:</p>
  
  <pre><code>try
  {
      DatabaseUpdate()
  }
  catch (SQLException e)
  when (driver == "MySQL")
  {
      //MySQL specific error handling and wrapping up the exception
  }
  catch (SQLException e)
  when (driver == "Oracle")
  {
      //Oracle specific error handling and wrapping up of exception
  }
  ..
  </code></pre>
  
  <p>but this is again something that I can do within the same handler and delegate to different methods depending on the type of the driver. Does this make the code easier to understand? Arguably no.</p>
  
  <p>Another scenario that I can think of is something like:</p>
  
  <pre><code>try
  {
      SomeOperation();
  }
  catch(SomeException e)
  when (Condition == true)
  {
      //some specific error handling that this layer can handle
  }
  catch (Exception e) //catchall
  {
      throw;
  }
  </code></pre>
  
  <p>Again this is something that I can do like:</p>
  
  <pre><code>try
  {
      SomeOperation();
  }
  catch(SomeException e)
  {
      if (condition == true)
      {
          //some specific error handling that this layer can handle
      }
      else
          throw;
  }
  </code></pre>
  
  <p>Does using the 'catch, when' feature make exception handling faster because the handler is skipped as such and the stack unwinding can happen much earlier as when compared to handling the specific use cases within the handler? Are there any specific use cases that fit this feature better which people can then adopt as a good practice?</p>