记录pyqt4应用程序中的所有异常

Bra*_*eis 11 python logging pyqt

使用标准python logging api记录pyqt4应用程序中的所有异常的最佳方法是什么?

我尝试在try中包装exec_(),除了块,并记录异常,但它只记录应用程序初始化的异常.

作为临时解决方案,我在try中包含了最重要的方法,除了块,但这不是唯一的方法.

dF.*_*dF. 16

你需要覆盖 sys.excepthook

def my_excepthook(type, value, tback):
    # log the exception here

    # then call the default handler
    sys.__excepthook__(type, value, tback) 

sys.excepthook = my_excepthook
Run Code Online (Sandbox Code Playgroud)