Community
Participate
Working Groups
Given the following class: public class A { public static String a() { try{ } catch (Exception e) { B.b(); //this will have the same effect: //throw new Exception(); } finally { return ""; } } } class B { public static void b() throws Exception { } } Eclipse incremental compilter will not flag the possible Exception that is thrown by B.b(); The key is in the nested Exception. If the return is taken out of the finally clause and put at the end of the method a(); then eclipse will pick up the error. Also reproducible in 2.1.3
If you remove the return statement from finally block, you'll observe that the exception analysis is working as expected. The thrown exception in catch block is superceded by the return in finally block. Any such exception is intercepted by the finally block, and since it doesn't complete normally, it gets lost. This behavior is mandated by the JLS analysis for code reachability, and other compilers agree with us. FYI - we provide an optional warning to diagnose such nasty finally blocks, which do not complete normally. Quizz: what does the following code return ? try { return 1; } finally { return 2; }
Answer: 2 Closing as invalid.
Yes, I think you're right. Thanks