32 lines
1.2 KiB
C#
32 lines
1.2 KiB
C#
using System;
|
|
using System.Windows;
|
|
|
|
namespace FahrzeugVerwaltung
|
|
{
|
|
public partial class App : Application
|
|
{
|
|
// Richtet die globale Fehlerbehandlung ein
|
|
protected override void OnStartup(StartupEventArgs e)
|
|
{
|
|
base.OnStartup(e);
|
|
AppDomain.CurrentDomain.UnhandledException += Domain_UnbehandelteAusnahme;
|
|
DispatcherUnhandledException += App_UnbehandelteAusnahme;
|
|
}
|
|
|
|
// Zeigt nicht abgefangene Fehler an
|
|
private void App_UnbehandelteAusnahme(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;
|
|
}
|
|
|
|
// Meldet schwere Ausnahmen
|
|
private void Domain_UnbehandelteAusnahme(object sender, UnhandledExceptionEventArgs e)
|
|
{
|
|
MessageBox.Show($"Ein kritischer Fehler ist aufgetreten:\n{((Exception)e.ExceptionObject).Message}",
|
|
"Kritischer Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
}
|