// -------------------------------------------------------------------------------------------------------------------- // // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // // // Interaction logic for App.xaml // // -------------------------------------------------------------------------------------------------------------------- namespace HandBrakeWPF { using System; using System.Windows; using Caliburn.Micro; using HandBrake.ApplicationServices.Exceptions; using HandBrakeWPF.ViewModels; /// /// Interaction logic for App.xaml /// public partial class App { /// /// Initializes a new instance of the class. /// public App() { Application.Current.Dispatcher.UnhandledException += this.Dispatcher_UnhandledException; AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); } /// /// Non-UI Thread expection handler. /// /// /// The sender. /// /// /// The UnhandledExceptionEventArgs. /// private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { this.ShowError(e.ExceptionObject); } /// /// Handle unhandled exceptions. UI thread only. /// /// /// The sender. /// /// /// The DispatcherUnhandledExceptionEventArgs. /// private void Dispatcher_UnhandledException( object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { this.ShowError(e.Exception); e.Handled = true; } /// /// Show an error dialog for the user. /// /// /// The exception. /// private void ShowError(object exception) { try { IWindowManager windowManager = IoC.Get(); if (windowManager != null) { ErrorViewModel errorView = new ErrorViewModel(); if (exception.GetType() == typeof(GeneralApplicationException)) { GeneralApplicationException applicationException = exception as GeneralApplicationException; if (applicationException != null) { errorView.ErrorMessage = applicationException.Error; errorView.Solution = applicationException.Solution; errorView.Details = applicationException.ActualException.ToString(); } } else { errorView.Details = exception.ToString(); } windowManager.ShowDialog(errorView); } } catch (Exception) { MessageBox.Show("An Unknown Error has occured. \n\n Exception:" + exception, "Unhandled Exception", MessageBoxButton.OK, MessageBoxImage.Error); } } } }