when i ran this program the error was ....... except.java:22:unreachable statement System.out.println("print 7"; 1 error >execution finished why is this error? when i take of the return statement at 1,it runs perfectly printing ... output rint 4 print 6 so,folks please help me solve this riddle... thanks Edited By Corey McGlone: Added CODE Tags [ July 16, 2003: Message edited by: Corey McGlone ]
pradeepbill, what happens I think is the following: 1.the compiler determines that an exception is thrown in the try block (for sure!) 2.the exception thrown in the try block is correctly caught by one of the catch statements 3 then since all the catch blocks have a return statement, it means that the code after the finally block can never execute. If for example you try to replace the try body with: if (true) throw new RuntimeException(); you wills e that the code compiles ok! Since the compiler can NOT determine anymore that an exception is always thrown at runtime. Anb BTW this has nothing really to do with exceptions, but program flow. This is very similar with:
where you get again a compiler error since "1" is never reachable.
You can read more in JLS 14.20 (unreachable statements) Hope it helps Miki Edited By Corey McGlone: Added CODE Tags [ July 16, 2003: Message edited by: Corey McGlone ]
Miki<br /> <br />SCJP 1.4, SCBCD 1.3
Joined: Jul 15, 2003
thanks miki ...ur reasoning helped me understand the flow control.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com