title: Java - Why cannot type parameters be in a catch clause?
body: <p>I know that generic types cannot extends Throwable and I understand that this doesn't make sense because type erasure (exceptions are thrown only at runtime) and other subtle things.</p>
  
  <p>However Java allows a type parameter to be bounded by Throwable in fact the following code is legal</p>
  
  <pre><code>class MyClass&lt;T extends Throwable&gt; { /*body of the class */ }
  </code></pre>
  
  <p>What is illegal is the use of the <code>T</code> parameter in a catch clause</p>
  
  <pre><code>try { //do something that throws exception //  }
  catch(T e) /* ILLEGAL!!! DOESN'T COMPILE */ {}
  </code></pre>
  
  <p>The only reason that I can understand about this constraint is that the type parameter, because erasure, is replaced by its bounding type, in this case <code>Throwable</code>.
  But type parameters could be bounded also by more than one bounding type so I could have this situation</p>
  
  <pre><code>class MyClass&lt;T extends Object &amp; Throwable&gt; [*]
  </code></pre>
  
  <p>in such case <code>T</code> is replaced after erasure by <code>Object</code> and I know that an <code>Object</code> (that is not of type <code>Throwable</code>) variable cannot be inside a catch clause.</p>
  
  <p>Let me know if this is the reason about this Java constraint. Thanks.</p>
  
  <p>EDIT: 
  [*] As davidxxx make me notice, this class declaration doesn't compile because <code>Throwable</code> is not an inteface.</p>