This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query reg. try catch finally

 
Manish Jaju
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a program, if it uses finally block, it will be executed. Is there any possiblity so that it(finally block) should not get executed in any condition. Please clarify.
 
Alain Boucher
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well... the main goal of a finally statement is that we are almost sure that it will be execute if exceptions are throw. If you don't want it to be executed just don't put a finally statement... or use a boolean in your finally

boolean doFinally = true;

try{

}catch (Throwable e){
doFinnaly = false;
}finally{
if (doFinally){
//Statement
}
}


But this is stupid code...
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know, the only regular way to have a finally block not executed is to call System.exit(x) in the try- or catch-block.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic