title: Java 8 - throw multiple generic checked exceptions in lambda
body: <p>In a project I am working at, I have found a class which wraps all methods of its super-class in some elaborate exception handling. It looks similar to that:</p>
  
  <pre><code>public void method1() throws ExceptionA {
      String exceptionString = "";
      try {
          super.method1();
      } catch (ExceptionA e) {
           exceptionString = // &lt;convert the exception to string in an elaborate way&gt;
           throw e;
      } finally {
           // &lt;an elaborate logger call which uses value of exceptionString&gt;
      }
  }
  
  public void method2() throws ExceptionB, ExceptionC {
      String exceptionString = "";
      try {
          super.method2();
      } catch (ExceptionB | ExceptionC e) {
           exceptionString = // &lt;convert the exception to string in elaborate way&gt;
           throw e;
      } finally {
           // &lt;an elaborate logger call which uses value of exceptionString&gt;
      }
  }
  
  // ... &lt;a bunch of other methods like this&gt;
  </code></pre>
  
  <p>I immediately though "Wow, how could would it be to have one generic wrapper and just call it in every of these methods. The class would be like 10x shorter!".
  So I got to work.</p>
  
  <p>This is where I got stuck:</p>
  
  <pre><code>private interface ThrowingMethod&lt;E extends Exception&gt; {
      void run() throws E;
  }
  
  public &lt;E extends Exception&gt; void wrapMethod(ThrowingMethod&lt;E&gt; method) throws E {
      String exceptionString = "";
      try {
          method.run();
      } catch (Exception e) {
           exceptionString = // &lt;convert the exception to string in an elaborate way&gt;
           throw e;
      } finally {
           // &lt;an elaborate logger call which uses value of exceptionString&gt;
      }
  }
  
  public void method1() throws ExceptionA {
      wrapMethod(super::method1); // works
  }
  
  public void method2() throws ExceptionB, ExceptionC {
      wrapMethod(super::method2); // Error in Eclipse: "Unhandled exception type Exception"
  }
  
  // ... &lt;a bunch of other methods like this&gt;
  </code></pre>
  
  <p>In conclusion, this approach works for methods that throws only one type of checked exception. When method throws multiple checked exceptions, Java assumes that the exception type is <code>Exception</code>.</p>
  
  <p>I tried to add more generic parameters to <code>ThrowingMethod</code> and <code>wrapMethod</code> but it doesn't change anything.</p>
  
  <p>How can I get a functional interface to work with multiple generic exceptions?</p>