How are exceptions actually implemented in assembly?

Jason Orendorff jason at jorendorff.com
Wed Jan 23 11:41:49 EST 2002


Hung Jung Lu wrote:
> So, how is C (hence Python) exception handling actually implemented?

Python exception handling is implemented using ordinary C.
Functions that need to raise exceptions return NULL.  When the
interpreter finds that a function has returned null, it updates
the traceback and either moves to the appropriate handler or
returns NULL itself.

(The None object is not the same thing as NULL, at the C level.)

Some C implementations have weird features that provide some sort
of exception-like behavior; also the C standard provides
setjmp()/longjmp() which is vaguely similar.  Python uses neither.

## Jason Orendorff    http://www.jorendorff.com/




More information about the Python-list mailing list