Skip to content

Learn: Error Handling

Four short tutorials that build up your working knowledge of Python exceptions from the ground up. Each one is a Jupyter notebook — read it in the browser, and edit and run any code cell directly on the page.

The tutorials build on each other, so working through them in order is the fastest path. Each takes roughly fifteen to twenty minutes.

The sequence

  1. Your first exceptiontry/except, handling common errors like ZeroDivisionError and FileNotFoundError.
  2. Exception types — the built-in exception hierarchy, catching specific exceptions, the Exception base class.
  3. Raising exceptions — using raise to signal errors, and when raising is the right response.
  4. Cleanup with finallyfinally, else, and context managers for reliable resource cleanup.

Before you start

You'll get more from these if you're already comfortable with Python functions and basic control flow. The Functions and Conditional logic guides cover the ground you need.

You don't need Python installed locally — every tutorial runs in your browser. If you'd rather run them on your own machine, each notebook has a download button in the top-right corner.