File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • 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
  • 0
  • 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: 2399
  • 0
  • 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
  • 0
  • 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: 47292
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question is answered here.
 
Rajdeep Biswas
Ranch Hand
Posts: 187
Eclipse IDE Java Opera
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic