• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Query reg. try catch finally

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic