[Python-Dev] setjmp/longjmp exception handling (was: More informative error messages)

Martin v. Löwis martin at v.loewis.de
Thu Oct 23 16:30:16 EDT 2003


"Brett C." <bac at OCF.Berkeley.EDU> writes:

> The basic idea is to keep a stack of jmp_buf points.

This is an old implementation strategy for exceptions in C++; e.g. GNU
g++ uses it with -fsjlj-exception option. It is generally discouraged
as it is *really* expensive: it requires a lot of memory per jmpbuf,
and it requires that the memory is filled.

In addition, for Python, there would be no simplification: each stack
frame needs to perform "all" DECREFs. To convert this to exception
handling, you would get very many nested try-catch blocks, as each
allocation of some object would need to be followed with a try-catch
block. So if you have 5 objects allocated in a function, you would
need a nesting of 5 levels - i.e. up to column 40.

Regards,
Martin




More information about the Python-Dev mailing list