• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

execution of finally

 
Nikhil Sun
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,

Just a simple query this.If I have a try catch finally block.I know the statement that the finally block is always executed no matter what.But I am also aware that the finally block does not get executed if there is a System.exit(0).
I just want to know when does the finally block fail to execute:
1)When the System.exit(0) is in the try block OR
2)When the System.exit(0) is in the catch block.

A silly question this but I want to know the answer immediately and I can't write a simple code to test right now.
 
Srikanth Ramu
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)When the System.exit(0) is in the try block before an execption is thrown then Catch and Finally block will not be executed.
2) When the System.exit(0) is in the Catch block then Finally block will not be executed.

Hope this helps
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally block will not be executed. No matter what.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the reasons why good programs should never (well, hardly ever) System.exit().
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nikhil Sun:
...I want to know the answer immediately and I can't write a simple code to test right now.

Are you working on a machine that does not have a JDK installed?
 
Nikhil Sun
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Marc I am not working/practising from home.Atleast not yet.And I don't havejdk installed on my system either .I was just reading up some articles and wanted to know some simple things like the topic I have posted.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic