aspose file tools*
The moose likes Beginning Java and the fly likes execution of finally Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "execution of finally " Watch "execution of finally " New topic
Author

execution of finally

Nikhil Sun
Ranch Hand

Joined: Nov 13, 2005
Posts: 108
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

Joined: Feb 20, 2007
Posts: 76
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

Finally block will not be executed. No matter what.


[My Blog]
All roads lead to JavaRanch
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
One of the reasons why good programs should never (well, hardly ever) System.exit().


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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?


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Nikhil Sun
Ranch Hand

Joined: Nov 13, 2005
Posts: 108
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: execution of finally