diff --git a/App.xaml.cs b/App.xaml.cs index 7b9b068..2a34773 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -9,6 +9,33 @@ namespace AnilistListConverter; /// public partial class App : Application { + protected override void OnStartup(StartupEventArgs e) + { + base.OnStartup(e); + // Add a global exception handler + AppDomain.CurrentDomain.UnhandledException += (sender, args) => + { + Exception ex = (Exception)args.ExceptionObject; + ShowErrorAndShutdown(ex); + }; + + // Also catch UI thread exceptions + DispatcherUnhandledException += (sender, args) => + { + Exception ex = args.Exception; + args.Handled = true; + ShowErrorAndShutdown(ex); + }; + } + + private void ShowErrorAndShutdown(Exception ex) + { + // Display the error in a message box + MessageBox.Show($"An unexpected error occurred: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + + // Close the app after the user clicks OK + Environment.Exit(1); + } }