Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #53030

Re: Missing something on exception handling in Python 3

References <CANc-5Uztbwz5cYk6K8vdLdjaFSPOO4qmROvPoUqfGFCnW6JVqA@mail.gmail.com> <521C0B62.1030004@mrabarnett.plus.com> <CANc-5Uyi_EXHLHbe9v7U8iNL00iCO8T-JMnaiAUmcB5sz-qd_A@mail.gmail.com> <521C19F0.50605@stoneleaf.us>
Date 2013-08-27 00:00 -0500
Subject Re: Missing something on exception handling in Python 3
From Skip Montanaro <skip@pobox.com>
Newsgroups comp.lang.python
Message-ID <mailman.255.1377579638.19984.python-list@python.org> (permalink)

Show all headers | View raw


I found this question/answer on Stack Overflow:

http://stackoverflow.com/questions/15123137

but after fiddling around with it, I can't find a solution that works
for Python 3.2 and 3.3, let alone 2.x.  In 3.2, exceptions have both
__cause__ and __context__ attributes.  I tried setting both to None
(in 3.2), but I still get the full double traceback:

>>> try: 1/0
... except ZeroDivisionError:
...    exc = TypeError()
...    exc.__context__ = None
...    exc.__cause__ = None
...    raise exc
...
Error in sys.excepthook:
IndexError: tuple index out of range

Original exception was:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 6, in <module>
TypeError

The sys.excepthook error is because I have a custom interactive
sys.excepthook, which is itself apparently broken in Python 3.2.

I've looked at PEP 409 and 415, but just get more confused.

*sigh*

Maybe I'll try again tomorrow when I've had a bit of sleep... and take
a closer look at Ethan's suggestion.

Skip

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Missing something on exception handling in Python 3 Skip Montanaro <skip@pobox.com> - 2013-08-27 00:00 -0500
  Re: Missing something on exception handling in Python 3 Steven D'Aprano <steve@pearwood.info> - 2013-08-27 09:22 +0000

csiph-web