[Python-3000] sys.exc_info() (original) (raw)

Antoine Pitrou solipsis at pitrou.net
Sat May 31 15:59:24 CEST 2008


Mark Hammond <mhammond skippinet.com.au> writes:

In both Python 2.x and 3 (a few months old build of Py3k though), the traceback isn't the same. For Python 2.0 you could write it like:

def handleexception(): ... raise sys.excinfo()[0], sys.excinfo()[1], sys.excinfo()[2] Its not clear how that would be spelt in py3k though (and from what I can see, sys.excinfo() itself has an uncertain future in py3k).

sys.exc_info() will remain, it's just that the returned value will be (None, None, None) if we are not in an except block in any of the currently active frames in the thread. In the case above it would return the current exception (the one caught in one of the enclosing frames).

By the way, another interesting sys.exc_info() case:

def except_yield(): try: raise TypeError except: yield 1

def f(): for i in except_yield(): return sys.exc_info()

Right now, running f() returns (None, None, None). But with rewritten exception stacking, it may return the 3-tuple for the TypeError raised in except_yield().

Regards

Antoine.



More information about the Python-3000 mailing list