finally clause

The last part of a try statement, which always runs, whether the try block succeeded, failed or returned early.

In more detail

Use it for clean-up, such as closing a file, that must happen no matter what. The else clause, by contrast, runs only when the try block raised nothing. A with statement is usually a neater way to guarantee clean-up.

Related terms

Taught in

References

Certification courses