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

Bad error recovery when 'catch' without 'try' is found

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 8
    • None
    • tools
    • None
    • b65
    • Verified

    Description

      The recovery logic applied when 'catch' is found w/o a matching 'try' is too weak and leads to confusing error messages, especially when lambda expression support is enabled.

      class Test {
          void test() {
              catch(Exception e) { e.printStackTrace(); }
          }
      }

      produces the following errors:

      Test.java:984: error: 'catch' without 'try'
              catch(Exception e) { e.printStackTrace(); }
              ^
      Test.java:984: error: lambda expressions are not supported in -source 1.8
              catch(Exception e) { e.printStackTrace(); }
                                 ^
        (use -source 8 or higher to enable lambda expressions)
      Test.java:984: error: -> expected
              catch(Exception e) { e.printStackTrace(); }
                                ^
      Test.java:984: error: not a statement
              catch(Exception e) { e.printStackTrace(); }
                   ^
      Test.java:984: error: ';' expected
              catch(Exception e) { e.printStackTrace(); }
                                                         ^

      Attachments

        Activity

          People

            vromero Vicente Arturo Romero Zaldivar
            mcimadamore Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: