我已通过以下方式在启动例程中在我的应用程序(C#、WPF、.NET4)中注册了全局异常处理程序:
AppDomain.CurrentDomain.UnhandledException += (sender, args) => HandleException(args.ExceptionObject as Exception);
Application.Current.DispatcherUnhandledException += (sender, args) => {
HandleException(args.Exception);
args.Handled = true;
};
其中 HandleException() 记录异常并显示带有一些附加信息的 MessageBox。
现在,我的应用程序在某些客户计算机上时常崩溃,其中未调用 HandleException()。 Windows 显示以下消息:
在 WindowsEventLog 中,我得到以下条目:
条目1:
Name der fehlerhaften Anwendung: proconact.exe, Version: 1.0.0.1365, Zeitstempel: 0x511531df
Name des fehlerhaften Moduls: PresentationFramework.ni.dll, Version: 4.0.30319.588, Zeitstempel: 0x504db27d
Ausnahmecode: 0xc00000fd
Fehleroffset: 0x002ef05b
ID des fehlerhaften Prozesses: 0x1bec
Startzeit der fehlerhaften Anwendung: 0x01ce0b5dce4030a6
Pfad der fehlerhaften Anwendung: C:\Program Files (x86)\proconact_sck\proconact.exe
Pfad des fehlerhaften Moduls: C:\windows\assembly\NativeImages_v4.0.30319_32\PresentationFramewo#\c627e9b7f10b01db43645284e601f255\PresentationFramework.ni.dll
Berichtskennung: d8d69f94-777a-11e2-b4b0-b4b52f2aad4f
条目2:
Fehlerbucket 3482664247, Typ 5
Ereignisname: CLR20r3
Antwort: Nicht verfügbar
CAB-Datei-ID: 0
Problemsignatur:
P1: proconact.exe
P2: 1.0.0.1365
P3: 511531df
P4: PresentationFramework
P5: 4.0.0.0
P6: 504db27d
P7: 329d
P8: 0
P9: System.StackOverflowException
P10:
Angefügte Dateien:
d:\Temp\WER6E9F.tmp.WERInternalMetadata.xml
Diese Dateien befinden sich möglicherweise hier:
C:\Users\roger\AppData\Local\Microsoft\Windows\WER\ReportArchive\AppCrash_proconact.exe_b0fabce1f86d1f843de5b5b4692a3e8ecd928_2c77f03d
Analysesymbol:
Es wird erneut nach einer Lösung gesucht: 0
Berichts-ID: d8d69f94-777a-11e2-b4b0-b4b52f2aad4f
Berichtstatus: 0
我该怎么做才能处理异常(主要是为了获取堆栈跟踪以分析异常发生的位置)?
最佳答案
有些异常无法捕获,甚至 AppDomain.UnhandledException 也无法捕获。因为它们太令人讨厌了,无法允许托管代码继续运行。
StackOverflowException 就是类似的心脏病发作,臭名昭著,以至于这个网站因此得名。没有足够的堆栈空间来执行常见的托管代码执行任务,例如运行抖动。 ExecutionEngineException 是另一种异常,由被破坏的垃圾收集堆触发,在 .NET 4.0 及更高版本中无法捕获。
所以不,表演结束了,剩下的就是 WER 对话框和 Windows 事件日志条目了。 SO 总是由错误引起的,您需要修复它。
关于wpf - 全局异常处理程序不会捕获某些异常(例如 StackoverflowException),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14897497/