finally

The finally keyword is used to define a block of code following a try/catch exception block. The finally block is optional, and appears after the try block and after any catch blocks. The code in a finally block is always executed once, regardless of how the code in a try block executes. In normal execution, control reaches the end of the try block and then proceeds to the finally block, which typically performs any necessary cleanup.

Note that if control leaves the try block because of a return, continue, or break statement, the contents of the finally block are still executed before control transfers out of the try block.

If an exception occurs in the try block, and there is an associated catch block to handle the exception within the method, control transfers first to the catch block, and then to the finally block. If there is not a local catch block to handle the exception, control transfers first to the finally block, and then moves up the series of prior method calls until the exception can be handled.