您必须使用该异常,并且如果希望事件循环结束,则必须调用
quit()(或
exit())方法。
import sysimport tracebackfrom PyQt5 import QtWidgets, QtGui, QtCoreclass ErrorApp: # ... def raise_error(self): assert Falsedef excepthook(exc_type, exc_value, exc_tb): tb = "".join(traceback.format_exception(exc_type, exc_value, exc_tb)) print("error catched!:") print("error message:n", tb) QtWidgets.QApplication.quit() # or QtWidgets.QApplication.exit(0)sys.excepthook = excepthooke = ErrorApp()ret = e.app.exec_()print("event loop exited")sys.exit(ret)
输出:
error catched!:error message: Traceback (most recent call last): File "main.py", line 28, in raise_error assert FalseAssertionErrorevent loop exited
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)