• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to avoid the execution of finally block?

 
Shahir Deo
Ranch Hand
Posts: 80
Hibernate Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to avoid the execution of finally block in Exception Handling??
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want to avoid it? It is optional.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The whole point of the finally block is to have something that will execute no matter what happens. If you don't want it to run, get rid of it. If you have it and you want to avoid it, you're not using it right.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question is answered here.
 
Rajdeep Biswas
Ranch Hand
Posts: 224
1
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want to shave hair on a bald head, and then grow the hair?
Or just think reverse?

If you do not want hair, leave the head bald (do not add finally).
If you want the hair, then grow hair (or add finally).
But please do not shave and then grow the hair. The bald man is victimized.

And please do not mind.
 
Saurabh Rana
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would someone want to avoid Finally block Execution. But if you just want to know a case when finally block would not be executed , then a System.exit would cause it.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saurav Rana wrote:Why would someone want to avoid Finally block Execution. But if you just want to know a case when finally block would not be executed , then a System.exit would cause it.


So would unplugging the computer. Or a meteor strike. Or the OS context switching to a different thread or process and never switching back. Or a bug in the JVM. Or a literal bug on the motherboard short-circuiting something.

But all of those--including System.exit()--just come down do "What can stop the JVM from executing any more instructions?" They have nothing to do with finally in particular, and if that's really what the question was about, then it was a rather silly question to start with.
 
Sateesh Kumar Allu
Greenhorn
Posts: 9
Chrome Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any other cases
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You pour a cup of coffee inside the computer case and burn out the wiring.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic