• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About Exception Handling

 
ahmad razaa
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For my own sanity:

 
Javin Paul
Ranch Hand
Posts: 295
Eclipse IDE Firefox Browser Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Hrishikesh Yeshwant Alshi
Ranch Hand
Posts: 62
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic