# traceback
# 概述
# 示例
import traceback
cnt = 0
def func():
global cnt
cnt += 1
if cnt < 3:
func()
else:
raise Exception('This is the error message.')
if __name__ == "__main__":
try:
func()
except:
print(f'Traceback error: {traceback.format_exc()}')
"""
Traceback error: Traceback (most recent call last):
File "/Users/lei/workspace/program/test/webserver.py", line 13, in <module>
func()
File "/Users/lei/workspace/program/test/webserver.py", line 7, in func
func()
File "/Users/lei/workspace/program/test/webserver.py", line 7, in func
func()
File "/Users/lei/workspace/program/test/webserver.py", line 9, in func
raise Exception('This is the error message.')
Exception: This is the error message.
"""