title: Possible syntax for multi-type catch blocks in C#?
body: <p>Here are two previous questions regarding this topic:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/136035/catch-multiple-exceptions-at-once">Catch multiple Exceptions at once?</a></li>
  <li><a href="https://stackoverflow.com/questions/791390/more-elegant-exception-handling-than-multiple-catch-blocks">More Elegant Exception Handling Than Multiple Catch Blocks?</a></li>
  </ul>
  
  <p>I was working today and thought this might be an appropriate syntax should this feature ever be added to the C# language. Anyone have any opinions about it?</p>
  
  <p>The type of <code>e</code> must be a base type or interface of every exception type listed.</p>
  
  <p><strong>Edit</strong>: In this example, the catch block handles either <code>ArgumentNullException</code> or <code>ArgumentOutOfRangeException</code> and places the exception instance in a variable of type <code>ArgumentException</code> called <code>e</code>. It doesn't handle any other type of <code>ArgumentException</code> other than the two listed. I think there was some confusion about the associativity of the <code>,</code> and the <code>as</code>.</p>
  
  <p><strong>Edit 2:</strong> If the listed exceptions all upcast to a variable of the type of <code>e</code>, then the code compiles cleanly to MSIL without any casts or explicit type checks, making it faster (potentially significantly) than the current syntax of catching <code>ArgumentException</code> followed by a <code>throw;</code> if it's not one of the two you intended. The problem is even more obvious if you're catching <code>Exception</code> and checking for two possible types to handle and rethrowing if it's something else.</p>
  
  <pre><code>try
  {
  }
  catch (ArgumentNullException, ArgumentOutOfRangeException as ArgumentException e)
  {
  }
  </code></pre>