JDK-8000484 : Bad error recovery when 'catch' without 'try' is found
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2012-10-05
  • Updated: 2013-06-11
  • Resolved: 2012-11-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b65Fixed
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(); }
                                                   ^
Comments
Waiting for review
30-10-2012