TracebackΒΆ
traceback
provides an interface to print stack traces of Python programs. It exactly mimics the behaviour of the Python interpreter when it prints a stack trace.
import traceback
try:
5/0
except:
traceback.print_exc()
Traceback (most recent call last):
File "<ipython-input-1-5b35d724d9df>", line 4, in <module>
5/0
ZeroDivisionError: division by zero