aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes When finally{} won't be reached? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "When finally{} won Watch "When finally{} won New topic
Author

When finally{} won't be reached?

Jan Osykowski
Ranch Hand

Joined: Jul 15, 2010
Posts: 41
Hey guys,

My question is in the subject, when it will not be reached? I remember that I read in the book that there is such a case but now I can't find this part when it happenss.

Cheers,
Jan.
Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

When JVM terminate before reaching the finally statement, for example try to put
System.exit(0); in try block.


Hope this helps.


SCJP6 96% | SCWCD5 81% | SCDJWS5 79%
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Finalyy is always reacable untill you exit you JVM using system.exit()


SCJP6.0,My blog Ranchers from Delhi
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Below code will be more useful for your understanding


Avishkar Nikale
Ranch Hand

Joined: Aug 06, 2010
Posts: 173
Please correct me if I am wrong, in all cases where your thread terminates abruptly the finally will not run.


Regards,
Avishkar Nikale
Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

Avishkar Nikale wrote:Please correct me if I am wrong, in all cases where your thread terminates abruptly the finally will not run.


true if jvm terminate abruptly in try/catch block then finally wont execute.
Jan Osykowski
Ranch Hand

Joined: Jul 15, 2010
Posts: 41
Ok guys, thanks for the answers! This is the case that got away from me!
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Finally associate only with try/catch.
There should not be any finally without try/catch.
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

There should not be any finally with try atleast for unchecked exception
For checked exception catch is necessary unless method is declared to throw that excpetion
For example see the below code



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: When finally{} won't be reached?