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

Inconvenient span for multi-catch error diagnostics

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 15
    • 15
    • tools
    • None
    • b22

      Consider this source code:
      ---
      try {
      } catch (IllegalStateException | java.io.IOException ex) {
      }
      ---

      In jshell, this will produce the following error:
      | Error:
      | exception java.io.IOException is never thrown in body of corresponding try statement
      | } catch (IllegalStateException | java.io.IOException ex) {}
      | ^-------------------------------------------------------^

      Seems the span of the error is incovenient - there is no issue with the catch block as such, it is just with a single exception in the multi-catch.

      A better error span would be like:
      | Error:
      | exception java.io.IOException is never thrown in body of corresponding try statement
      | } catch (IllegalStateException | java.io.IOException ex) {}
      | ^-----------------^

            jlahoda Jan Lahoda
            jlahoda Jan Lahoda
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: