Given an Exception object (of unknown origin) is there way to obtain its traceback? I have code like this:
def stuff():
try:
.....
return us
Since Python 3.0[PEP 3109] the built in class Exception has a __traceback__ attribute which contains a traceback object (with Python 3.2.3):
>>> try:
... raise Exception()
... except Exception as e:
... tb = e.__traceback__
...
>>> tb
The problem is that after Googling __traceback__ for a while I found only few articles but none of them describes whether or why you should (not) use __traceback__.
However, the Python 3 documentation for raise says that:
A traceback object is normally created automatically when an exception is raised and attached to it as the
__traceback__attribute, which is writable.
So I assume it's meant to be used.