Community
Participate
Working Groups
Eclipse 2.1 M5 Build 200302061700 This code compiles without any problems: import java.io.*; import java.util.ArrayList; public class TestException { public ArrayList funcTest() { boolean returnNull = true; try { File file = new File("whatever string"); returnNull = file.createNewFile(); } finally { if (returnNull) return null; else return new ArrayList(); } } } I was expecting the compiler had complained because this method doesn't catch or throws IOException. Compiling with javac in a command prompt returns this error: C:\Temp>javac TestException.java TestException.java:10: unreported exception java.io.IOException; must be caught or declared to be thrown returnNull = file.createNewFile(); ^ 1 error
Duplicate of bug 30949. This is not a bug. javac 1.3.1 has a bug. The finally block returns. Therefore there is no uncaught exceptions. *** This bug has been marked as a duplicate of 30949 ***
According the language specification at http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#23665 3 - If execution of the try block completes abruptly because of a throw of a value V, 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 normally, then the try statement completes abruptly because of a throw of the value V. It should throw an IOException if the createNewFile() throw such an exception, no ? Unless I don't understand this spec :(
According to 'http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#5 894', the return statement in the finally block makes the finally block complete abruptly.
I see now that you're right. Thanks for the explanation. I Was confused because of javac 1.3.1 bug. This bug can be closed.