Forums Register Login

exceptions!

+Pie Number of slices to send: Send
class MyClass {
int show() {
try {
int k = 20/0;
return 10;
} catch(Exception e) {
int k = 10/0;
return 20;
}
finally {
System.out.println("in finally");
return 30;
}
}
public static void main(String args[]) {
System.out.println("In main");
System.out.println(new MyClass().show());
}
}
Hi! in the above program after executing the finally block, the exception thrown by the catch block is not handled by the default handler or it is not passed to the main method, why?
ashok.
+Pie Number of slices to send: Send
Hii..
If a finally block is specified after the catch block,then
regardless of whether the catch block itself throws an
exception,finally block is executed.Hence whatever exception
that is thrown in catch block will be suppressed.
Just comment the finally block..
The program will throws ArithmeticException
Hope this helps
chin
+Pie Number of slices to send: Send
the exception is not supressed if you allow the finally clause to end, just comment return 30;
+Pie Number of slices to send: Send
throwing the exception messsage is preceded by the return in the
finally clause
This happens in both exceptions wheather thrown in the try block or in the catch block
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 634 times.
Similar Threads
Exception
checked exceptions!
Reg. return from try-catch-finally
StackTrace
confusion with finally
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 19:07:00.