skip to content

The Exception Model

Raising and catching a single exception: the BaseException hierarchy, the full try/except/else/finally flow, chaining, custom classes and the EAFP idiom. The core of any error-handling round.

part ofPythonoverview, primer and where to startread it →
on this pageshow

questions

page 2 of 2

Why does keeping caught exceptions in a list hold whole call frames alive, and what do you store instead?

level: seniorimportance: nice to knowfreq 17%

basics

~10 s

An exception references its traceback, which references every frame it passed through, which references those frames' locals. Keeping the exception keeps all of it. Store traceback.TracebackException.from_exception(exc), or the rendered text, instead.

open as a page

showing 31–31 of 31