Какой лучший способ отловить ошибки в приложении wpf. Я уже добавил в свой app.xaml.cs следующее:
void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
var stringBuilder = new StringBuilder();
stringBuilder.AppendFormat("{0}\n", e.Exception.Message);
stringBuilder.AppendFormat(
"Exception handled on main UI thread {0}.", e.Dispatcher.Thread.ManagedThreadId);
// attempt to save data
var result = MessageBox.Show(
"Application must exit:\n\n" + stringBuilder.ToString() + "\n\nSave before exit?",
"app",
MessageBoxButton.YesNo,
MessageBoxImage.Error);
if (result == MessageBoxResult.Yes)
{
MessageBox.Show(e.Exception.InnerException.ToString());
MessageBox.Show(e.Exception.InnerException.Message.ToString());
}
// Return exit code
this.Shutdown(-1);
// Prevent default unhandled exception processing
e.Handled = true;
}
private void Application_Startup(object sender, StartupEventArgs e)
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
}
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Exception ex = e.ExceptionObject as Exception;
MessageBox.Show(ex.Message, "Uncaught Thread Exception", MessageBoxButton.OK, MessageBoxImage.Error);
}
Но я все еще получаю случаи, когда приложение вылетает и ошибка не отображается в окне сообщения. Как мне отладить такие ошибки? Журнал событий окон не показывает мне никакой полезной информации. И, конечно же, приложение отлично работает в IDE, так что это не очень помогает.