Module 7: Errors and debugging

Read tracebacks, handle errors with try/except, raise your own, and debug like a pro.

  1. Reading errors: Syntax errors stop the file before it runs, runtime errors stop at the bad line, logical errors give wrong answers silently; read a traceback from the bottom up.
  2. Handling errors: try the risky lines, except a named error, else runs only on success, finally always runs; the first matching except wins, so put specific ones first; raise your own errors.
  3. Debugging: Debug by finding the first wrong value (trace table or labelled prints); never use a bare except:, catch only the errors you expect.

Ends with a 13-question checkpoint (80% passes) and a mini project: Canteen Counter: the order form that never crashes.