This commit is contained in:
2024-10-13 16:34:46 +02:00
parent b6755ae77f
commit d7d7db8dd4
12 changed files with 140 additions and 85 deletions

View File

@@ -2,15 +2,50 @@
namespace Jugenddienst_Stunden;
/// <summary>
/// Die Hauptanwendungsklasse.
/// </summary>
public partial class App : Application {
/// <summary>
/// Initialisiert eine neue Instanz der <see cref="App"/>-Klasse.
/// </summary>
public App() {
InitializeComponent();
MainPage = new AppShell();
//UnhandledException: Wird gefangen, wenn eine Ausnahme in einem beliebigen nicht verwalteten Thread außerhalb des individuellen Kontexts auftritt.
AppDomain.CurrentDomain.UnhandledException += (sender, e) => {
if (e.ExceptionObject is Exception ex) {
HandleException(ex);
}
};
//UnobservedTaskException: Wird ausgelöst, wenn eine Ausnahme in einem asynchronen Task auftritt und nicht behandelt wird.
TaskScheduler.UnobservedTaskException += (sender, e) => {
HandleException(e.Exception);
e.SetObserved();
};
//Dispatcher: Hilft bei der Handhabung von UI-bezogenen Ausnahmen innerhalb des UI-Threads.
if (Current?.Dispatcher != null) {
Current.Dispatcher.Dispatch(async () => {
try {
// Anwendungscode hier
await Task.CompletedTask; // Dummy await to avoid CS1998
} catch (Exception ex) {
HandleException(ex);
}
});
}
MainPage = new AppShell();
}
private void HandleException(Exception ex) {
// Fehlerbehandlungscode
Console.WriteLine($"Globale Ausnahme: {ex?.Message}");
// Optional: Logging oder Benutzerbenachrichtigung
}
//protected override Window CreateWindow(IActivationState activationState) =>
//new Window(new AppShell()) {