From c5a2a15865e3310b3f8ae2eeab5cd54194687ad0 Mon Sep 17 00:00:00 2001 From: Damian Wessels Date: Tue, 8 Aug 2023 09:46:33 +0200 Subject: [PATCH] this fixes #5 Es wird nun ein Fehlermeldung angezeigt bei absturz --- StammGenerator/App.xaml.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/StammGenerator/App.xaml.cs b/StammGenerator/App.xaml.cs index b80fc9d..32e1c33 100644 --- a/StammGenerator/App.xaml.cs +++ b/StammGenerator/App.xaml.cs @@ -12,6 +12,7 @@ using System.Windows; using CodeMeter; using SewerStammGen.Shared; using System.Threading; +using System.Windows.Threading; namespace StammGenerator { @@ -58,6 +59,9 @@ namespace StammGenerator protected override void OnStartup(StartupEventArgs e) { if (_host == null) return; + + Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException; + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; _host.Start(); MainWindow? window = new MainWindow() { DataContext = _host.Services.GetRequiredService() }; @@ -65,5 +69,24 @@ namespace StammGenerator base.OnStartup(e); } + + private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + try + { + Exception ex = (Exception)e.ExceptionObject; + string text = "Ein Software fehler ist Aufgetreten. Bitte kontaktiere uns mit folgende Information:\n\n"; + MessageBox.Show(text + " " + ex.Message + "\n\n" + ex.StackTrace); + } + catch (Exception ex2) + { + MessageBox.Show("Fatal Non-UI error", ex2.Message, MessageBoxButton.OK, MessageBoxImage.Error); + } + } + + private void Current_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) + { + throw new NotImplementedException(); + } } }