Anatomy of a traceback
Module 07 taught the bottom-up reading. This is the reference: what each part of a traceback is, including the pieces newer Python versions added — the ^^^^ markers that point at the exact expression, the "Did you mean" suggestions, and the chained "During handling of the above exception" blocks.
Traceback (most recent call last): ① header — frames follow, outermost first
File "app.py", line 22, in main ② a frame: file, line, function
total = process(rows) ③ the source line of that frame
File "app.py", line 12, in process
return row["price"] * qty
~~~^^^^^^^^^ ④ 3.11+: exactly which expression failed
KeyError: 'price' ⑤ the exception type and message — START HERE
The above exception was the direct cause of the following exception: ⑥ chaining (raise … from e)
Traceback (most recent call last):
...
PricingError: could not price row 4 ⑦ the outer, higher-level error your code raised- Read ⑤ first, then find the last frame that is in your file, then look at ③/④ on that frame.
- A
SyntaxErrororIndentationErrorhas no frames — it happened before the program ran — and the caret points at (or just after) the problem. - "During handling of the above exception, another exception occurred" means your
exceptblock itself crashed. Fix the second one first; it is hiding the first. - 3.10+ adds
Did you mean: 'total'?to NameError and AttributeError. Trust it.
