[Python-Dev] PEP 344 (was: with_traceback)

Andrew Dalke dalke at dalkescientific.com
Sat Mar 3 01:41:39 CET 2007


On 3/2/07, Guido van Rossum <guido at python.org> wrote:
> So, despite the existence of libraries that pre-create exceptions, how
> bad would it really be if we declared that use unsafe? It wouldn't be
> hard to add some kind of boobytrap that goes off when pre-created
> exceptions are raised multiple times. If this had always been the
> semantics I'm sure nobody would have complained and I doubt that it
> would have been a common pitfall either (since if it doesn't work,
> there's no bad code abusing it, and so there are no bad examples that
> newbies could unwittingly emulate).

Here's code from os._execvpe which reraises an exception
instance which was created earlier

    saved_exc = None
    saved_tb = None
    for dir in PATH:
        fullname = path.join(dir, file)
        try:
            func(fullname, *argrest)
        except error, e:
            tb = sys.exc_info()[2]
            if (e.errno != ENOENT and e.errno != ENOTDIR
                and saved_exc is None):
                saved_exc = e
                saved_tb = tb
    if saved_exc:
        raise error, saved_exc, saved_tb
    raise error, e, tb

Would the boobytrap go off in this case?  I think it would,
because a "saved_exc" is raised twice.

        Andrew
        dalke at dalkescientific.com


More information about the Python-Dev mailing list