在pyqt4应用程序中记录所有异常 [英] Logging All Exceptions in a pyqt4 app
本文介绍了在pyqt4应用程序中记录所有异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用标准的python日志记录api在pyqt4应用程序中记录所有异常的最佳方法是什么?
What's the best way to log all of the exceptions in a pyqt4 application using the standard python logging api?
我尝试将exec_()封装在try中,除了块,然后记录其中的异常,但是它仅记录应用程序初始化中的异常.
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.
作为一种临时解决方案,我尝试了将try中最重要的方法(块除外)包装起来,但这并不是唯一的方法.
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.
推荐答案
def my_excepthook(type, value, tback):
# log the exception here
# then call the default handler
sys.__excepthook__(type, value, tback)
sys.excepthook = my_excepthook
这篇关于在pyqt4应用程序中记录所有异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文