5 .net crash exception-handling exception
I'm trying to crash my WPF application, and capture the exception using the above new .NET 4 attribute.
I managed to manually crash my application by calling Environment.FailFast("crash");.
(I also managed to crash it using Hans's code from "How to simulate a corrupt state exception in .NET 4?".)
The application calls the above crashing code when pressing on a button. Here are my exception handlers:
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
DispatcherUnhandledException += app_DispatcherUnhandledException;
}
[HandleProcessCorruptedStateExceptions]
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
//log..
}
[HandleProcessCorruptedStateExceptions]
void CurrentDomain_FirstChanceException(object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e)
{
//log..
}
[HandleProcessCorruptedStateExceptions]
void app_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
//log..
}
Run Code Online (Sandbox Code Playgroud)
The //log... comment shown above is just for illustration; there's real logging code there.
在Visual Studio中运行时,会抛出异常,但它不会"冒泡"到这些异常处理程序块.当作为独立运行时(没有附加调试器),我没有得到任何日志,尽管我期望.
为什么会这样,以及如何使处理代码被执行?
| 归档时间: |
|
| 查看次数: |
7046 次 |
| 最近记录: |