• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

When finally{} won't be reached?

 
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.
 
Ranch Hand
Posts: 400
Hibernate Spring Java
  • 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.
 
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


 
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 Spring Java
  • 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



 
when your children are suffering from your punishment, tell your them it will help them write good poetry when they are older. Like this tiny ad:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!