Java Reference
In-Depth Information
statement
statement
. . .
}
finally
{
statement
statement
. . .
}
Examt:
PrintWriter out = new PrintWriter(filename);
try
{
writeData(out);
}
finally
{
out.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
512
513
However, we recommend that you don't mix
catch
and
finally
clauses in the
same
try
blockČsee
Quality Tip 11.3
.
S
ELF
C
HECK
9.
Why was the out variable declared outside the
try
block?
10.
Suppose the file with the given name does not exist. Trace the flow of
execution of the code segment in this section.