• 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

When finally block does not run?

 
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When finally block does not run?(try/catch)
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See Java Tutorials - The finally block.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Generally the finally block shouldn't be used except for "safety-net" situations. You should never rely on them to do their job for there is no guarantee that they will execute.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Brad Dwan wrote:Generally the finally block shouldn't be used except for "safety-net" situations. You should never rely on them to do their job for there is no guarantee that they will execute.



Hi Brad,

I think you're thinking of overriding the finalize() method, which is, as you say, not guaranteed to be executed. finally blocks, on the other hand, will always be executed after the corresponding try, with the single exception being that the finally block won't execute if the JVM exits (via System.exit() or a crash) during the try. That's an iron-clad guarantee.
 
Brad Dwan
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ernest Friedman-Hill wrote:

Brad Dwan wrote:Generally the finally block shouldn't be used except for "safety-net" situations. You should never rely on them to do their job for there is no guarantee that they will execute.



Hi Brad,

I think you're thinking of overriding the finalize() method, which is, as you say, not guaranteed to be executed. finally blocks, on the other hand, will always be executed after the corresponding try, with the single exception being that the finally block won't execute if the JVM exits (via System.exit() or a crash) during the try. That's an iron-clad guarantee.



My mistake. Noted. I can change a little of my own code then. :P
 
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

When finally block does not run?(try/catch)


When the try or catch blocks call System.exit()
EDIT: Oops, this was already said.
reply
    Bookmark Topic Watch Topic
  • New Topic