title: Why can't I have a catch for a checked exception for a call that throws a generic?
body: <p>I am working on a small helper that is supposed to invoke arbitrary code (passed in as lambda). The helper should catch certain exceptions, and throw them inside some wrapper. My "own" exceptions should not be wrapped but just re-thrown. </p>
  
  <p>I came up with this code:</p>
  
  <pre><code>@FunctionalInterface
  interface Processable&lt;T, X extends Throwable&gt; {
      public T apply() throws X;
  }
  
  class MyCheckedException extends Exception { ... }
  class MyCheckedExceptionWrapper extends MyCheckedException { ... }
  
  public class MyExceptionLogger&lt;T, X extends Throwable&gt; {
      public T process(Processable&lt;T, X&gt; processable) throws MyCheckedException {
          try {
              return processable.apply();
          } catch (MyCheckedException thrown) { // this line isn't accepted
              throw thrown;
          } catch (Exception | LinkageError thrown) {
              throw new MyCheckedExceptionWrapper(thrown);
          } catch (Throwable thrown) {
             ... just log
            return null; 
          }
      }
  }
  </code></pre>
  
  <p>The above gives a compile error:</p>
  
  <blockquote>
    <p>Unreachable catch block for MyCheckedException. This exception is never thrown from the try statement body MyExceptionLogger ...</p>
  </blockquote>
  
  <p>In other words: although <code>apply()</code> is defined to throw some <code>X extends Throwable</code> I can't catch a specific checked exception when invoking that method. </p>
  
  <p>I <em>know</em> that I can get to working code by catching <strong>Throwable</strong>, to then use <code>instanceof</code> checks - but I would like to understand <strong>why</strong> it is not possible to have a try/catch as outlined above.</p>