Logging All Exceptions in a pyqt4 app

2019-04-04 23:47发布

What's the best way to log all of the exceptions in a pyqt4 application using the standard python logging api?

I've tried wrapping exec_() in a try, except block, and logging the exceptions from that, but it only logs exceptions from the initialization of the app.

As a temporary solution, I wrapped the most important methods in try, except blocks, but that can't be the only way to do it.

1条回答
混吃等死
2楼-- · 2019-04-05 00:35

You need to override 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
查看更多
登录 后发表回答