• 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

K&B Exception Handling

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys!

Having read the K&B notes on Exception Handling, I have stumbled upon something fishy.

At one point the authors mention,

It is (the finally block) guaranteed to be called except in the special cases where the try or the catch code raises an uncaught exception or issues a System.exit()



At another point, they say,

...it(finally block) will always be invoked, regardless of whether an exception in the corresponding try is thrown or not, and regardless of whether a thrown exception is caught or not.




I find it quite hard to digest the two sentences which I think are contradictory. Anyways, I'd like to hear from you on this! Am I correct, or should I actually be "reading between the lines" ???



Thanks
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I think that the special cases are the ones where the JVM stops running. For example when you get an OutOfMemoryException. It doesn't make sence to run finally, when the entire system is out of memory..

Greetz
 
Anand Jayaraman
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Geoffrey!

Thanks for that, buddy! Now I get it.

And, again on the same note, can I blindly consider the finally block to run if there are no System.exit() statements, 'coz Errors like OutOfMemory and VirtualMachineError can't be helped???


Cheers!!!
 
Anand Jayaraman
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Chaps!!!

I missed out on something here.

I meant, in the SCJP exam, can I blindly consider the finally block to run if there are no System.exit() statements, 'coz Errors like OutOfMemory and VirtualMachineError occur as a one off case???

Thank You
 
Geoffrey Vlassaks
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anand,

Yes you can, even for return statements like the following code:



The value of "s" after this piece is "catch exception"

Greetz
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic