Skip to content

Instantly share code, notes, and snippets.

@constructor-igor
Created December 27, 2016 09:26
Show Gist options
  • Save constructor-igor/584763b19fb60bd980cfe3d2a848e376 to your computer and use it in GitHub Desktop.
Save constructor-igor/584763b19fb60bd980cfe3d2a848e376 to your computer and use it in GitHub Desktop.
UnhandledException in WPF
Dispatcher.CurrentDispatcher.UnhandledException += CurrentDispatcher_UnhandledException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
[HandleProcessCorruptedStateExceptions]
[SecurityCritical]
void CurrentDispatcher_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
var ex = e.Exception;
string message = ex.NameAndMessage();
string details = ex.GetDetailedMessage();
string title = "Unhandled exception in GUI dispatcher thread";
e.Handled = true;
}
[HandleProcessCorruptedStateExceptions]
[SecurityCritical]
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var ex = e.ExceptionObject as Exception;
var message = ex.NameAndMessage();
Environment.FailFast(ex.NameAndMessage());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment