From 9c3d55bf7ad8c9d373dd542e0321e94c8e457ee1 Mon Sep 17 00:00:00 2001
From: duheng <2784771470@qq.com>
Date: 星期五, 17 一月 2025 11:32:54 +0800
Subject: [PATCH] 更新ui报错提示,增加登录日志

---
 Desktop/HStation.Desktop.Xhs.Core/Program.cs |   31 ++++++++++++++++++++++++-------
 1 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/Desktop/HStation.Desktop.Xhs.Core/Program.cs b/Desktop/HStation.Desktop.Xhs.Core/Program.cs
index 712cea3..16dce32 100644
--- a/Desktop/HStation.Desktop.Xhs.Core/Program.cs
+++ b/Desktop/HStation.Desktop.Xhs.Core/Program.cs
@@ -1,6 +1,7 @@
 using DevExpress.LookAndFeel;
 using Mapster;
 using System.Reflection;
+using Yw.WinFrmUI;
 
 namespace HStation.Desktop
 {
@@ -29,11 +30,11 @@
                 System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-Hans");
 
                 //处理未捕获的异常
-                //Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
+                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                 //处理UI线程异常
-                //Application.ThreadException += Application_ThreadException;
+                Application.ThreadException += Application_ThreadException;
                 //处理非UI线程异常
-                //AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
+                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
 
                 Application.EnableVisualStyles();
                 Application.SetCompatibleTextRenderingDefault(false);
@@ -96,15 +97,31 @@
         private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
         {
             var ex = e.Exception;
-            Yw.LogHelper.Error("系统出现未知异常,ERROR:249", ex);
-            MessageBox.Show($"系统出现未知异常,请重启系统!\r\n{ex.Message}");
+            if (ex is Yw.Dto.InternalException internalEx)
+            {
+                Yw.LogHelper.Error("系统出现内部异常,ERROR:249", internalEx);
+                MessageBoxHelper.ShowError(internalEx.ErrorMsg);
+            }
+            else
+            {
+                Yw.LogHelper.Error("系统出现未知异常,ERROR:249", ex);
+                MessageBoxHelper.ShowError($"系统出现未知异常,请重启系统!\r\n{ex.Message}");
+            }
         }
 
         private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
         {
             var ex = e.ExceptionObject as Exception;
-            Yw.LogHelper.Error("系统出现未知异常,ERROR:255", ex);
-            MessageBox.Show($"系统出现未知异常,请重启系统!\r\n{ex.Message}");
+            if (ex is Yw.Dto.InternalException internalEx)
+            {
+                Yw.LogHelper.Error("系统出现内部异常,ERROR:249", internalEx);
+                MessageBoxHelper.ShowError(internalEx.ErrorMsg);
+            }
+            else
+            {
+                Yw.LogHelper.Error("系统出现未知异常,ERROR:255", ex);
+                MessageBoxHelper.ShowError($"系统出现未知异常,请重启系统!\r\n{ex.Message}");
+            }
         }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3