Enhanced rethrow disabled in lambdas

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P3
    • 8
    • Affects Version/s: 8
    • Component/s: tools
    • b108
    • Verified

      In the following lambda:

      [1:33:03 PM] Brian Goetz: static Runnable composeWithExceptions(Runnable a, Runnable b) {
              return () -> {
                  try {
                      a.run();
                  }
                  catch (Throwable e1) {
                      try {
                          b.run();
                      }
                      catch (Throwable e2) {
                          e1.addSuppressed(e2);
                      }
                      finally {
                          throw e1;
                      }
                  }
                  b.run();
              };
          }

      The compiler complains that throwing a Throwable is not allowed. If the lambda is refactored to an inner class instance, enhanced rethrow allows e1 to be rethrown.

            Assignee:
            Jan Lahoda
            Reporter:
            Brian Goetz
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: