How to catch and print the full exception traceback without halting/exiting the program?

后端 未结 15 2237
天命终不由人
天命终不由人 2020-11-22 13:46

I want to catch and log exceptions without exiting, e.g.,

try:
    do_stuff()
except Exception, err:
    print(Exception, err)
    # I want to print the entir         


        
15条回答
  •  [愿得一人]
    2020-11-22 14:02

    You want the traceback module. It will let you print stack dumps like Python normally does. In particular, the print_last function will print the last exception and a stack trace.

提交回复
热议问题