[Python-3000] sys.exc_info()
Adam Olsen
rhamph at gmail.com
Sat May 31 19:24:32 CEST 2008
On Sat, May 31, 2008 at 7:59 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> Mark Hammond <mhammond <at> 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 handle_exception():
>> ...
>> raise sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]
>>
>> Its not clear how that would be spelt in py3k though (and from what I can
>> see, sys.exc_info() 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().
What exception stacking? I thought we'd be using a simple per-thread
exception. I'd expect the yield statement to clear it, giving us
(None, None, None).
--
Adam Olsen, aka Rhamphoryncus
More information about the Python-3000
mailing list