The following snippet produces different output between python 2 & 3
# exc_info_test.py
import sys
def f():
try:
raise RuntimeError()
except Exception as e:
print("f:", sys.exc_info())
g()
def g():
print("g:", sys.exc_info())
f()
Output
> python2 exc_info_test.py
('f:', (<type 'exceptions.RuntimeError'>, RuntimeError(), <traceback object at 0x7f99aa4ccd70>))
('g:', (<type 'exceptions.RuntimeError'>, RuntimeError(), <traceback object at 0x7f99aa4ccd70>))
> python3 exc_info_test.py
f: (<class 'RuntimeError'>, RuntimeError(), <traceback object at 0x7fc14fb67d00>)
g: (None, None, None)
Though the behaviour difference is documented, it is too subtle to notice the difference
https://docs.python.org/2/library/sys.html
Here, “handling an exception” is defined as “executing or having executed an except clause.” For any stack frame, only information about the most recently handled exception is accessible.
https://docs.python.org/3/library/sys.html
Here, “handling an exception” is defined as “executing an except clause.” For any stack frame, only information about the exception being currently handled is accessible.
To make the difference highlighted, I suggest to document the sys.exc_info behaviour difference in Cheat Sheets or in an appropriate page.
The following snippet produces different output between python 2 & 3
Output
Though the behaviour difference is documented, it is too subtle to notice the difference
https://docs.python.org/2/library/sys.html
https://docs.python.org/3/library/sys.html
To make the difference highlighted, I suggest to document the
sys.exc_infobehaviour difference in Cheat Sheets or in an appropriate page.