aspose file tools
The moose likes Beginning Java and the fly likes avoid finally Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "avoid finally" Watch "avoid finally" New topic
Author

avoid finally

anarkali perera
Ranch Hand

Joined: Sep 10, 2009
Posts: 237
we know that finally block execute every time.But is there any other way to avoid the executing finally block without system.exit()?
Zandis Murāns
Ranch Hand

Joined: Aug 18, 2009
Posts: 174

yeah, do not write that block if you don't want to execute it. Or, create if statement that surrounds all the block:
anarkali perera
Ranch Hand

Joined: Sep 10, 2009
Posts: 237
no.this not i need.there is a way that is somthing automatically generated............
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32675
    
    4
anarkali perera wrote:we know that finally block execute every time.But is there any other way to avoid the executing finally block without system.exit()?
Yes. It's called bad design. If you wrote a "finally" block you intend to execute it, so you don't want to avoid execution.

You will find this question comes up here repeatedly. Look what the late Stan James wrote here.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9948
    
    6

Cambell is right. the whole POINT of a finally block is that is it code that HAS to run, regardless of what else happens in the try/catch block. You are effectively asking "How do i not run the code I said I have to run"?

To that i'd reply "which is it? do you need to run it, or do you need to not run it?"

You should only put code that has to be run every time in the finally block. If you don't need to always run it, DON'T put it in there.


Never ascribe to malice that which can be adequately explained by stupidity.
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3327

Well said by Campbell and fred rosenberger!

It would be other way around called as 'Self Contradiction' Moreover, it would be a mere waste of all - including the lines in your java source code, compilers efforts to get the code compiled, etc., ...


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32675
    
    4
But have you read what Stan wrote? That is such a beautiful quote
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3327

Yes of course. His verse is "Man, I hate when that happens"!

He was one such beautiful bartender. We miss him a lot!
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 915

God bless his soul.


My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: avoid finally
 
Similar Threads
finally clause
sequence generator with mysql
finally , finalize()
Web Apps
Is the sequence of output correct?