loop
← All sections

Module 4 · Functions, tuples, dictionaries, exceptions, and data processing

Exceptions

Real programs meet bad data and broken assumptions. Instead of letting them crash, you catch errors as they happen with try and except — then learn to test for and hunt down the bugs you write yourself.

Begin lesson 1 →
  1. 1Errors are part of the jobWhy every program meets errors — and the traceback Python shows when one stops it cold.
  2. 2try and exceptCatch an error the moment it happens and keep the program alive: ask forgiveness, not permission.
  3. 3Handling several kindsDifferent errors, different responses — multiple except branches, plus a catch-all for the rest.
  4. 4Exceptions you'll meetA field guide to the everyday ones: ZeroDivisionError, ValueError, TypeError and friends.
  5. 5Finding and fixing bugsErrors in your code, not the data: test every path, and hunt bugs with print debugging.
  6. 6QuizCheck your grip on tracebacks, try/except, branch order and common exceptions.