新增全局异常捕获

This commit is contained in:
shuaikangzhou 2024-01-02 23:11:29 +08:00
parent 8a1f6ad59e
commit e30b6396d2
2 changed files with 16 additions and 0 deletions

View File

@ -106,6 +106,7 @@ class ExportDialog(QDialog):
def set_total_msg_num(self, num):
self.total_msg_num = num
# b''+num +(1,1)
def export_finished(self):
self.export_button.setEnabled(True)

15
main.py
View File

@ -16,8 +16,22 @@ from app.config import version
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("WeChatReport")
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True)
widget = None
def excepthook(exc_type, exc_value, traceback_):
# 将异常信息转为字符串
# 在这里处理全局异常
error_message = ''.join(traceback.format_exception(exc_type, exc_value, traceback_))
msg = f"Exception Type: {exc_type.__name__}\nException Value: {exc_value}\ndetails: {error_message}"
logger.error(f'程序发生了错误:\n\n{msg}')
QMessageBox.critical(widget, "Unhandled Exception", msg, QMessageBox.Ok)
# 调用原始的 excepthook以便程序正常退出
sys.__excepthook__(exc_type, exc_value, traceback_)
# 设置 excepthook
sys.excepthook = excepthook
class ViewController(QWidget):
def __init__(self):
super().__init__()
@ -66,6 +80,7 @@ if __name__ == '__main__':
font = QFont('微软雅黑', 12) # 使用 Times New Roman 字体,字体大小为 14
app.setFont(font)
view = ViewController()
widget = view
try:
# view.loadPCDecryptView()
view.loadMainWinView()