[Pyrex] nested exception bug

Eric Huss e-huss at netmeridian.com
Mon Jun 18 23:22:55 UTC 2007


There's a subtle bug when calling functions from within an exception
handler.  The program below illustrates the problem (it ends up raising
the wrong exception).

Python went through the same issues (fixed in 1.5), and their solution was
to make a backup of the current exception into the frame object and
restore it when the frame exited.  I'm guessing that Pyrex would need to
do something similar using local variables (possibly changing
__Pyx_ReRaise to take the exception from the local variables instead of
from the tstate object).  There might be some subtle issues with
__Pyx_AddTraceback, too.

def bar():
    try:
        raise TypeError
    except TypeError:
        pass

def foo():
    try:
        raise ValueError
    except ValueError:
        print 'got value error'
        bar()
        raise

-Eric



More information about the Pyrex mailing list