This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pitrou
Recipients Arfrever, amaury.forgeotdarc, pitrou, scoder, vstinner
Date 2010-02-15.12:37:38
SpamBayes Score 1.110223e-15
Marked as misclassified No
Message-id <1266237551.3343.6.camel@localhost>
In-reply-to <1266234431.02.0.908409501983.issue7173@psf.upfronthosting.co.za>
Content
> I tried several times to debug it myself, but I don't understand the
> exception cleanup macros in ceval.c (UNWIND_EXCEPTION_HANDLER and
> friends, new in Py3). If someone can get me set up to debug them, I
> can give it another shot. I assume there are a couple of invariants
> involved in them? Is there any interaction with generators that I
> should know about?

The exception state (what sys.exc_info() gives you) in 3.x is lexically
scoped (which it wasn't in 2.x).
Which means that given:
    try:
        1/0
    except ZeroDivisionError:
        # A
        try:
            [][0]
        except IndexError:
            # B
            pass
        # C

The exception state in C will hold the ZeroDivisionError, not the
IndexError (it is the reverse in 2.x). For that, each try/except block
needs to save the previous exception state; it is saved on the frame's
stack. When the try/except block is left, UNWIND_EXC_HANDLER is used to
restore the previous exception state.

And, yes, there's an interaction with generators, because "yield" can be
invoked from an except block. In that case, we have to temporarily
restore the caller's exception state. See the SWAP_EXC_STATE() call in
YIELD_VALUE. Also, the generator's exception state is restored when
resuming it, which is done in line 1162 and following in ceval.c.
History
Date User Action Args
2010-02-15 12:37:45pitrousetrecipients: + pitrou, amaury.forgeotdarc, scoder, vstinner, Arfrever
2010-02-15 12:37:40pitroulinkissue7173 messages
2010-02-15 12:37:39pitroucreate