traceback模块的作用

traceback模块被用来跟踪异常返回信息. 如下例所示:

1
2
3
4
5
import traceback
try:
    raise SyntaxError, "traceback test"
except:
    traceback.print_exc()

将会在控制台输出类似结果:

1
2
3
4
Traceback (most recent call last):
  File "H:PythonWorkSpaceTestsrcTracebackTest.py", line 3, in <module>
    raise SyntaxError, "traceback test"
SyntaxError: traceback test

posted on 2017-10-15 14:07  深海屿鹿  阅读(146)  评论(0编辑  收藏  举报

导航