3 ms·
Exception handlers in CPython work by having an instruction store the offset to the start of the handler code which is stored on a stack attached to the frame (
by dom0 9y ago
Exception handlers in CPython work by having an instruction store the offset to the start of the handler code which is stored on a stack attached to the frame (iirc). So the cost of a "try:" block is pretty low (for Python, anyway).
The handlers themselves are pretty basic, an "except SomeError" pretty much translates to "if isinstance(exc, SomeError):".