Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80744 > unrolled thread
| Started by | Veek M <vek.m1234@gmail.com> |
|---|---|
| First post | 2014-11-14 12:48 +0630 |
| Last post | 2014-11-14 18:56 +0630 |
| Articles | 2 — 1 participant |
Back to article view | Back to comp.lang.python
Python 3.x (beazley): __context__ vs __cause__ attributes in exception handling Veek M <vek.m1234@gmail.com> - 2014-11-14 12:48 +0630
Re: Python 3.x (beazley): __context__ vs __cause__ attributes in exception handling Veek M <vek.m1234@gmail.com> - 2014-11-14 18:56 +0630
| From | Veek M <vek.m1234@gmail.com> |
|---|---|
| Date | 2014-11-14 12:48 +0630 |
| Subject | Python 3.x (beazley): __context__ vs __cause__ attributes in exception handling |
| Message-ID | <m44ad2$ece$1@dont-email.me> |
In 'Chained Exceptions' - Beazley pg:626
------------
try:
pass
except ValueError as e:
raise SyntaxError('foo bar') from e
-------------
Here, if ValueError is raised and SyntaxError is then raised.. 'e' contains
__cause__ which points to the ValueError Traceback. He goes on to say:
---------------
A more subtle example of exception chaining involves exceptions raised
within another exception handler. For example:
def error(msg):
print(m) # Note: typo is intentional (m undefined)
try:
statements
except ValueError as e:
error("Couldn't parse configuration")
-------------------
Here, 'error' generates an inadvertent exception. What i don't understand is
this bit:
------------------
For implicit chaining, the _ _context_ _ attribute of an exception instance
e contains a reference to previous exception.
---------------------
Why is he saying that 'e' contains a reference in __context__ to the
exception generated by 'error' ?? Is that correct? Surely, the exception
generated by 'error' will refer to 'e'? WTH??
For Implicit errors, there is no 'e'! Additionally, how would you go about
using __context__ if the exception is generated implicitly? Book pages:
imgur.com/bwpYq8T imgur.com/inZQv5J
[toc] | [next] | [standalone]
| From | Veek M <vek.m1234@gmail.com> |
|---|---|
| Date | 2014-11-14 18:56 +0630 |
| Message-ID | <m44vtj$ln7$1@dont-email.me> |
| In reply to | #80744 |
It's been answered here: http://stackoverflow.com/questions/26924045/python-3-x-beazley-context-vs- cause-attributes-in-exception-handling?noredirect=1#comment42403467_26924045
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web