Python - start interactive debugger when exception would be otherwise thrown

后端 未结 4 1177
-上瘾入骨i
-上瘾入骨i 2021-02-04 03:16

Is there any way to make a python program start an interactive debugger, like what import pdb; pdb.set_trace() instead of actually throwing an exception?

I

4条回答
  •  南笙
    南笙 (楼主)
    2021-02-04 04:12

    This question is quite old, so this is mainly for future me

    try:
        ...
    except:
        import traceback, pdb, sys
        traceback.print_exc()
        print ''
        pdb.post_mortem()
        sys.exit(1)
    

提交回复
热议问题