wood burning stoves 2.0*
The moose likes Java in General and the fly likes How to avoid the execution of finally block? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to avoid the execution of finally block?" Watch "How to avoid the execution of finally block?" New topic
Author

How to avoid the execution of finally block?

Shahir Deo
Ranch Hand

Joined: Mar 19, 2013
Posts: 80

How to avoid the execution of finally block in Exception Handling??


Knowledge enlivens the soul.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Why do you want to avoid it? It is optional.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Oct 13, 2005
Posts: 38465
    
  23
The question is answered here.
Rajdeep Biswas
Ranch Hand

Joined: Mar 26, 2012
Posts: 186

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.


The biggest gamble will be to ask a question whose answer you know in that it will challenge your theory | www.TechAspire.blogspot.in
Saurav Rana
Greenhorn

Joined: Jul 05, 2012
Posts: 6
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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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
 
subject: How to avoid the execution of finally block?