Summary: | Compiler did not detect uncaught exception | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Philipe Mulet <philippe_mulet> |
Component: | Core | Assignee: | Philipe Mulet <philippe_mulet> |
Status: | RESOLVED WONTFIX | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | CC: | john, rodrigo |
Version: | 2.0 | ||
Target Milestone: | 2.0 M6 | ||
Hardware: | PC | ||
OS: | Windows 2000 | ||
Whiteboard: |
Description
Philipe Mulet
2002-04-16 12:00:25 EDT
Simpler test case: [package p1; public class X { public Object run(Object result) throws Exception { try { System.out.println("aaa"); } catch (Throwable e) { throw e; } finally { return result; } } }] Javac 1.2.2 did also accept this code. The reason why we accept this code is that the offending code actually never ends up throwing the Throwable exception. It is intercepted by the finally block which instead will return some value. So in practice, the offending exception doesn't need to be caught. JLS 14.19.2 precisely describe this situation: 14.19.2 Execution of try-catch-finally A try statement with a finally block is executed by first executing the try block. Then there is a choice: ... If the run-time type of V is not assignable to the parameter of any catch clause of the try statement, then the finally block is executed. Then there is a choice: ... If the finally block completes abruptly for reason S, then the try statement completes abruptly for reason S (and the throw of value V is discarded and forgotten). --------- In the original test case, the exception thrown within the catch block isn't handled inside this try statement, but the finally block makes it irrelevant. javac has a bug. |