Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Help Java E The finally Keyword

Related Tutorials


 
 

Share on Google+Share on Google+

The finally Keyword

Advertisement
The finally is a Java keyword that is used to define a block that is always executed in a try−catch−finally statement.

The finally Keyword  

     

The finally is a Java keyword that is used to define a block that is always executed in a try−catch−finally statement. In java, there are three clauses named try, catch and finally used as exception handler components. A finally block typically contains cleanup code that recovers from partial execution of a try block.

It is always a good practice to use finally clause after the try and catch block to handle an unexpected exception occurred in the try block. It becomes possible because the finally block always executes when the try block exits and it is also useful to write the cleanup code within the finally block. The finally block is executed surely whether the exception is generated or not. This is a Java keyword therefore it may not be used as identifiers i.e. you cannot declare a variable or class with this name in your Java program. It is used when the finally block is executed after the execution exits the try block and any associated catch clauses regardless of whether an exception was thrown or caught. 

The syntax of declaring a final type variable is: 

try {

/ Normal execution path 

  ??????.
    ??????  

} catch (ExampleException ee)

/  deal with the ExampleException

   ??????.
 
??????

}

finally {

   / This optional section is executed upon
 termination of any of the try or catch blocks /above

     ??????..
 
??????.

}
 

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 13, 2009

Related Tutorials

Discuss: The finally Keyword   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
sankar
May 13, 2012
finally block

try{ int x=10/2; } finally{ system.out.println("i am from finally"); } here compiler will not compliant.any one can help why compiler will not compliant.
Johnd246
May 29, 2014


How significantly of an special post, keep on posting much better half eceebekbkfgg
DMCA.com