| Author |
About Exception Handling
|
ahmad razaa
Greenhorn
Joined: Jan 03, 2011
Posts: 10
|
|
I have a confusion about this code.
This code is giving the results:
1
4
Java.lang.RuntimeException
As we handled the RuntimeException , then why its throwing the exception and why its not run finally block?
Early answer will be appreciated.
[Edit: added code tags and indented code - Ankit]
|
 |
Hrishikesh Yeshwant Alshi
Ranch Hand
Joined: Dec 06, 2010
Posts: 62
|
|
For my own sanity:
|
Write your code as if the person who maintains it is a homicidal maniac who knows where you live.
OCPJP6/SCJP6 86%
|
 |
Javin Paul
Ranch Hand
Joined: Oct 15, 2010
Posts: 276
|
|
Hi Yeshwant,
I have re formatted your code for better understanding
Here you see you have just one "try" block and all catch block and finally is for that only , there is no " try" block to catch RuntimeException and that's why its not getting caught and after printing what's there in finally its terminating.
If you modify code like below you will be able to catch RuntimeException.
Thanks
Javin
|
http://javarevisited.blogspot.com - java classpath - Java67 - java hashmap - java logging tips java interview questions Java Enum Tutorial
|
 |
Hrishikesh Yeshwant Alshi
Ranch Hand
Joined: Dec 06, 2010
Posts: 62
|
|
@ahmad razaa.
Javin explains it correctly.
@Javin,
This question was asked by ahmad razaa. I was about to post the same reply but you did it just before me. You explanation makes it very clear.
|
 |
 |
|
|
subject: About Exception Handling
|
|
|