Here is an EntityException which occurs when the EntityFramework can not contact the Sql database, but just the database is closed, the rest of the app can still work fine. So, is there a way? I tried to use
AppDomain.CurrentDomain.UnhandledException
but the app still exit in release mode. Thanks!
Asked
Active
Viewed 66 times
0

Cagaya Coper
- 75
- 1
- 12
-
1Possible duplicate of [WPF global exception handler](http://stackoverflow.com/questions/1472498/wpf-global-exception-handler) – sknt Oct 19 '16 at 12:03
1 Answers
3
I believe that you're looking for this:
public partial class App
{
public App()
{
this.Dispatcher.UnhandledException += OnDispatcherUnhandledException;
}
private async void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
await ErrorService.HandleError(e.Exception, "An unhandled exception occurred", true, true);
e.Handled = true;
}
}

Mr.B
- 3,484
- 2
- 26
- 40