try-finally Statement

The try-finally statement differs from its try-except brethren in that it is not used to handle exceptions. Instead it is used to maintain consistent behavior regardless of whether or not exceptions occur. The finally suite executes regardless of an exception being triggered within the try suite.

Example

try:
    try_suite
finally:
    finally_suite # executes regardless of
exceptions

When an exception does occur within the try suite, execution jumps immediately to the finally suite. When all the code in the finally suite completes, the exception is reraised for handling at the next higher layer. Thus it is common to see a try-finally nested as part of a try-except suite.