previous | start | next

Syntax 14.4: The finally Clause

  try
{
   statement
   statement

   ...
}
finally
{
   statement
   statement

   ...
}

Example:

 
BufferedReader in = null;
try
{
in = new BufferedReader(
new FileReader(filename));
purse.read(in);
}
finally
{
if (in !=null) in.close();
}

Purpose:

To execute one or more statements that may generate exceptions, and to execute the statements in the finally clause whether or not an exception occured. 


previous | start | next