What exceptions are and why they happen
18-minute lesson · module-exceptions-01
You are previewing this course as a guest
Read anything and run any exercise you like. It all runs in your own browser, so nothing here is saved: no XP, no progress, and the AI tutor needs an account. Sign in and your work starts counting.
What exceptions are and why they happen
18-minute lesson · module-exceptions-01
- Define "exception" as Python's mechanism for signaling a runtime error.
- Distinguish exceptions from syntax errors (one is at parse time, the other at run time).
- Read a traceback to find the call site that raised an exception.
- Predict which standard exception type each common mistake will raise.
Source attribution
Status: adapted
How to Think Like a Computer Scientist: Interactive Edition — source · Exceptions / Intro / Runtime stack and the raise command
Adaptation notes. Reading rewritten in our voice. Traceback example uses a small recipe function (consistent with the Functions chapter's "named recipe" metaphor). Hidden tests don't actually trigger exceptions — they check that the student function returns the *name* of the exception they'd predict, which forces careful reading without requiring try/ except (which is covered two lessons later).
License notes. Original chapter is GNU FDL 1.3 (Brad Miller and David Ranum). No verbatim text from the original is reproduced here.