Skip to content

Latest commit

 

History

History
20 lines (14 loc) · 661 Bytes

how-to-print-the-full-traceback-without-halting-the-program.md

File metadata and controls

20 lines (14 loc) · 661 Bytes

打印异常堆栈

stackoverflow连接1

stackoverflow连接2

最简单的方法就是用traceback模块,例子:

import traceback

try:
    raise Exception('this is exception')
except Exception as e:
    traceback.print_exc()
    #or
    print(traceback.format_exc())

此方法在Python2和Python3都适用,在stackoverflow的原链接中还有很多说到其它方法的答案。