What exactly does a finally
block in exception handling perform?
It holds code that should always be executed, regardless of whether an exception occurs.
For example, if you have opened a file, you should close it in the finally
block to ensure that it will always be closed; if you closed it in the try
block, an earlier exception would cause execution to jump straight to the catch
block and skip closing the file.
See the Java tutorials for more details.