Get full traceback

前端 未结 5 1089
陌清茗
陌清茗 2020-12-12 22:55

How can i get full traceback in the following case, including the calls of func2 and func functions?

import traceback

def func():
         


        
5条回答
  •  一生所求
    2020-12-12 23:13

    Stack trace is collected when exception bubbles up. So you should print traceback on top of desired stack:

    import traceback
    
    def func():
        raise Exception('Dummy')
    
    def func2():
        func()
    
    
    try:
        func2()
    except:
        traceback.print_exc()
    

提交回复
热议问题