Community
Participate
Working Groups
When the finally clause includes return, no compile-time message is generated for uncaught exceptions in the try clause. When I save this code in Eclipse, no compile-time error is reported. (However, without the return statement in the finally block, the uncaught exception is detected.) public class UncaughtNotDetected { void test() { try { thrower(); } finally { return; } } void thrower() throws java.lang.Exception { throw new java.lang.Exception(); } } For comparison, when compiled using JDK 1.3.1 javac, the following is reported UncaughtNotDetected.java:4: unreported exception java.lang.Exception; must be caught or declared to be thrown Using Eclipse Versoin R1.0 Build 0.137
This is not a bug in the Eclipse compiler. As described in Bug 13906, the test () method should, as described JLS(2nd edition) 14.19.2, throw the exception, and hence the compiler should consider the code valid. *** This bug has been marked as a duplicate of 13906 ***
Correction of earlier comment, inserting missing "NOT": This is not a bug in the Eclipse compiler. As described in Bug 13906 referring to JLS(2nd edition) 14.19.2, test() should NOT throw the exception, and hence the compiler should consider the code valid, as it does. JDK 1.3.1 javac is wrong.
Indeed this is a javac bug.