def excepthook(excType, excValue, tracebackobj):
"""Rewritten "excepthook" function, to display a message box with details about the exception.
@param excType exception type
@param excValue exception value
@param tracebackobj traceback object
"""
separator = '-' * 40
notice = "An unhandled exception has occurred\n"
tbinfofile = io.StringIO()
traceback.print_tb(tracebackobj, None, tbinfofile)
tbinfofile.seek(0)
tbinfo = tbinfofile.read()
errmsg = '%s: \n%s' % (str(excType), str(excValue))
sections = [separator, errmsg, separator, tbinfo]
msg = '\n'.join(sections)
# Create a QMessagebox
error_box = QtWidgets.QMessageBox()
error_box.setText(str(notice)+str(msg))
error_box.setWindowTitle("Grid Control - unhandled exception")
error_box.setIcon(QtWidgets.QMessageBox.Critical)
error_box.setStandardButtons(QtWidgets.QMessageBox.Ok)
error_box.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)
# Show the window
error_box.exec_()
sys.exit(1)
评论列表
文章目录