Cladude code 更改

This commit is contained in:
2026-05-14 18:26:22 +08:00
parent 268f4baf99
commit df3da9d9cb
4 changed files with 107 additions and 48 deletions

View File

@@ -283,6 +283,24 @@ namespace CapMachine.Wpf
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
//非UI线程未捕获异常处理事件 (例如自己创建的一个子线程)
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
//首次抛出(含被吞掉的)异常也落日志,便于排查闪退场景下原生互操作异常
AppDomain.CurrentDomain.FirstChanceException += (s, fce) =>
{
try
{
var ex = fce.Exception;
//只关心严重异常,避免日志被刷爆
if (ex is AccessViolationException
|| ex is System.Runtime.InteropServices.SEHException
|| ex is StackOverflowException
|| ex is OutOfMemoryException)
{
LogService?.Error($"[FirstChance-FATAL] {ex.GetType().Name}: {ex.Message}\r\n{ex.StackTrace}");
}
}
catch { /* 异常处理函数中绝不能再抛 */ }
};
}