[Python-Dev] except Exception as err, tb [was: with_traceback]

Jim Jewett jimjjewett at gmail.com
Fri Mar 2 21:35:10 CET 2007

Guido van Rossum wrote:

> Since this can conceivably be going on in parallel in multiple
> threads, we really don't ever want to be sharing whatever object
> contains the head of the chain of tracebacks since it mutates at every
> frame bubble-up.

So (full) exceptions can't be unitary objects.

In theory, raising an already-instantiated instance could indicate "no
traceback", which could make pre-cooked exceptions even lighter.

Otherwise, there is no way to make exceptions reference their
traceback directly.  Using a property which depends on both the
exception and the frame asking (catching frame?  thread?) is ...
probably worse than keeping them separate.

    >>> except MyException as err, tb

isn't so awful, and makes it clear that the traceback is no longer
needed after the more typical

    >>> except MyException as err
    ...         # no raise statements needing a context or cause


More information about the Python-Dev mailing list