previous | start | next

Syntax 15.4: The finally Clause

 
try
{
   statement
   statement
   . . .
}
finally
{
   statement
   statement
   . . .
}

Example:

 
FileReader reader = new FileReader(filename);
try
{
   readData(reader);
}
finally
{
   reader.close();
}

Purpose:

To ensure that the statements in the finally clause are executed whether or not the statements in the try block throw an exception.

previous | start | next