Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When finally{} won't be reached?

 
Jan Osykowski
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 400
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When JVM terminate before reaching the finally statement, for example try to put
System.exit(0); in try block.


Hope this helps.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finalyy is always reacable untill you exit you JVM using system.exit()
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below code will be more useful for your understanding


 
Avishkar Nikale
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please correct me if I am wrong, in all cases where your thread terminates abruptly the finally will not run.
 
Minhaj Mehmood
Ranch Hand
Posts: 400
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok guys, thanks for the answers! This is the case that got away from me!
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally associate only with try/catch.
There should not be any finally without try/catch.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic