I have a handler for unhandled exceptions in the App class of my project. It is for the purpose of setting up a Send Feedback button.
App.xaml.cs
private void Application_DispatcherUnhandledException(
object sender, DispatcherUnhandledExceptionEventArgs e)
{
try
{
// Try to collect feedback with dialog.
new ApplicationExceptionDialog(e).ShowDialog();
}
catch
{
MessageBox.Show(
"A problem has occurred with the program:\r\n\r\n" +
e.Exception.Message + "\r\n\r\n" +
"The application will now exit.",
"Application Error",
MessageBoxButton.OK,
MessageBoxImage.Error);
}
finally
{
Application.Current.Shutdown(1); // ← Is this okay?
}
}
Question
Other than handling various exceptions, when all else has failed, what is the proper way to exit the application after an unhandled exception?
Edit
This question is specific to WPF applications. I also have unmanaged code in the application to make logins more secure. I haven't had any problems with it, but I need to make sure that if problems arise, the exit process used is the best option.