LESSON 1.07 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW
Exceptions and context managers
Watch an exception travel down the call stack, and see which code still runs.
Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 3 controls and 3 checks, in this lesson and every other.
Go Pro · $8.25/moEXPLAINER · 1.07 · EXCEPTION BAY4 FRAMES · TRACEBACK 1 · EXCEPTION IN SCALE
01
Stage 1 of 6 · Raise
raise makes a ValueError exception object. It holds its args and a traceback.
Explain it simply
You see the call stack on the left, with the newest call on top. main called work, and work called scale with n set to -1. So the raise line runs. It makes an exception: an object that reports the error, in red on the right.
The stack holds 4 frames: the module, main, work and scale. scale raised a ValueError. Its args hold the message n < 0. Its traceback has 1 entry: scale, line 24.
frame and nameobjectid and referenceexception, traceback, bad valueresult and output
Toy: 4 frames · CPython 3.12 rules · ids are stand-ins · frames a traceback keeps are not drawn
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
An exception object holds its class, its args and its traceback.
PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
- 5 more stages and 3 live controls
- 2 mix-up cards and 3 predict-then-reveal checks
- Watch it as a narrated video, in three voices
- Every Pro lesson and capstone · 656 in total
$99 a year, or $15 a month. Cancel any time.