2025-08-31 17:11:58 +02:00

32 lines
1.2 KiB
C#

using System;
using System.Windows;
namespace FahrzeugVerwaltung
{
public partial class App : Application
{
// startet die Anwendung und richtet Fehlerbehandlung ein
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
DispatcherUnhandledException += App_DispatcherUnhandledException;
}
// behandelt UI-Ausnahmen
private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
MessageBox.Show($"Ein unerwarteter Fehler ist aufgetreten:\n{e.Exception.Message}",
"Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
e.Handled = true;
}
// behandelt kritische Ausnahmen
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
MessageBox.Show($"Ein kritischer Fehler ist aufgetreten:\n{((Exception)e.ExceptionObject).Message}",
"Kritischer Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}