R. David Murray added the comment:
What caught me out was more like this (but more complicated so it wasn't
obvious the line mentioned wasn't part of the exception chain; in fact it
looked like it was since it was a line that could very well have raised the
exception in question):
rdmurray@pydev:~/python/p36>cat temp.py
def do_something():
try:
foo()
except Exception:
print('caught in do_something')
raise
def foo():
with cm():
print('all is well')
class cm:
def __enter__(self):
return self
def __exit__(*args, **kw):
raise Exception('exception in __exit__')
do_something()
rdmurray@pydev:~/python/p36>./python temp.py
all is well
caught in do_something
Traceback (most recent call last):
File "temp.py", line 20, in <module>
do_something()
File "temp.py", line 3, in do_something
foo()
File "temp.py", line 10, in foo
print('all is well')
File "temp.py", line 18, in __exit__
raise Exception('exception in __exit__')
Exception: exception in __exit__
The confusing line in the traceback is "print('all is well')", which obviously
isn't raising the exception.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue25538>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com