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: 1046
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: 1046
Below code will be more useful for your understanding
Avishkar Nikale
Ranch Hand
Joined: Aug 06, 2010
Posts: 173
posted Sep 04, 2010 13:39:10
0
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: 1046
Finally associate only with try/catch.
There should not be any finally without try/catch.
Shanky Sohar
Ranch Hand
Joined: Mar 17, 2010
Posts: 1046
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
subject: When finally{} won't be reached?