Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53030 > unrolled thread
| Started by | Skip Montanaro <skip@pobox.com> |
|---|---|
| First post | 2013-08-27 00:00 -0500 |
| Last post | 2013-08-27 09:22 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
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
| From | Skip Montanaro <skip@pobox.com> |
|---|---|
| Date | 2013-08-27 00:00 -0500 |
| Subject | Re: Missing something on exception handling in Python 3 |
| Message-ID | <mailman.255.1377579638.19984.python-list@python.org> |
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
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve@pearwood.info> |
|---|---|
| Date | 2013-08-27 09:22 +0000 |
| Message-ID | <521c6fe2$0$11100$c3e8da3@news.astraweb.com> |
| In reply to | #53030 |
On Tue, 27 Aug 2013 00:00:36 -0500, Skip Montanaro wrote: > 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: Yes, "raise from None" only works in Python 3.3. My way of dealing with this is to use "raise from None" and just accept that 3.1 and 3.2 users will see double tracebacks :-( All the more reason to encourage people to go straight to 3.3 or better and skip 3.1 and 3.2 :-) -- Steven
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web