Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8019521

Enhanced rethrow disabled in lambdas

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 8
    • 8
    • 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.

            jlahoda Jan Lahoda
            briangoetz Brian Goetz
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: