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..
}
The //log...
comment shown above is just for illustration; there's real logging code there.
When running in Visual Studio, an exception is thrown, but it doesn't 'bubble' up to those exception handler blocks. When running as standalone (without the debugger attached), I don't get any log, despite what I expect.
Why is it so, and how to make the handling code to be executed?