Sometimes, we want to throw exception information is written in python program storage medium, this time we can use the package to read exception traceback information:
import traceback
try:
raise Exception("发现异常")
except Exception:
print("追溯异常:\n"+'---'*20)
print(traceback.format_exc())
operation result:
追溯异常:
------------------------------------------------------------
Traceback (most recent call last):
File "<ipython-input-3-a0443d867f20>", line 4, in <module>
raise Exception("发现异常")
Exception: 发现异常
Of course, this is only suitable for use in small-scale projects. If it is larger server projects, consider using a more integrated exception management framework, such as: Sentry