• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

About Exception Handling

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Ranch Hand
Posts: 62
Netbeans IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For my own sanity:

 
Ranch Hand
Posts: 300
Eclipse IDE Firefox Browser Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic