-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.xaml.cs
41 lines (34 loc) · 1.07 KB
/
App.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System.Configuration;
using System.Data;
using System.Windows;
namespace AnilistListConverter;
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
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);
}
}