Last Updated: June 6, 2026
A try block runs code that might fail. A catch block reacts when it does. The finally block runs cleanup that needs to happen either way: closing a connection, releasing a lock, writing an audit line. This lesson covers what finally is, how it interacts with try and catch, the execution order in each scenario, the rare cases where it doesn't run, and two well-known traps (return and throw inside finally) that turn helpful cleanup into silent bugs.