[Python-Dev] Re-raise in absence of an "active" exception

Anders J. Munch ajm at flonidan.dk
Tue Jun 29 08:45:54 EDT 2004


"Martin v. Löwis" [mailto:martin at v.loewis.de] wrote:
> 
> I'm actually surprised that the exception is cleared when the
> function that has the exception handler completes. Where does that
> happen? The current exception is in the thread state, not in the
> frame, after all.

eval_frame calls set_exc_info and reset_exc_info to do a save/restore
to the frame object.

Effectively there's a stack of exceptions, but since it's bound to
frames interesting cases like this occur:

try:
    point_A
except:
    try:
        point_B
    except:
        pass
    raise

==> NameError: name 'point_B' is not defined

(Refugees from C++ might expect the 'point_A' exception instead.)

Method extraction brings the frame object into play for a different
result:

def b():
    try:
        point_B
    except:
        pass
try:
    point_A
except:
    b()
    raise

==> NameError: name 'point_A' is not defined

- Anders



More information about the Python-Dev mailing list