Skip to content

Commit

Permalink
Avalonia default unhandled exception
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Jan 7, 2024
1 parent 9572a41 commit 97d9562
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sandbox/AvaloniaApplication1/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ public static AppBuilder BuildAvaloniaApp()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace()
.UseR3(ex => Logger.Sink?.Log(LogEventLevel.Error, "R3", null, "R3 Unhandled Exception {0}", ex)); // add this line
.UseR3(); // add this line
}
13 changes: 9 additions & 4 deletions src/R3.Avalonia/AppBuilderR3InitializeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@ namespace Avalonia; // Avalonia namespace

public static class AppBuilderR3InitializeExtensions
{
public static AppBuilder UseR3(this AppBuilder builder, Action<Exception> unhandledExceptionHandler)
public static AppBuilder UseR3(this AppBuilder builder)
{
// need to delay setup, initialize provider(dispatcher) need to determine platform
return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultObservableSystem());
}

public static AppBuilder UseR3(this AppBuilder builder, Action<Exception> unhandledExceptionHandler)
{
return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultObservableSystem(unhandledExceptionHandler));
}

public static AppBuilder UseR3(this AppBuilder builder, DispatcherPriority priority, Action<Exception> unhandledExceptionHandler)
{
return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultObservableSystem(unhandledExceptionHandler,priority));
return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultObservableSystem(unhandledExceptionHandler, priority));
}

public static AppBuilder UseR3(this AppBuilder builder, int framesPerSecond, Action<Exception> unhandledExceptionHandler)
{
return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultObservableSystem(unhandledExceptionHandler,framesPerSecond));
return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultObservableSystem(unhandledExceptionHandler, framesPerSecond));
}

public static AppBuilder UseR3(this AppBuilder builder, DispatcherPriority priority, int framesPerSecond, Action<Exception> unhandledExceptionHandler)
{
return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultObservableSystem(unhandledExceptionHandler,priority, framesPerSecond));
return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultObservableSystem(unhandledExceptionHandler, priority, framesPerSecond));
}
}
8 changes: 7 additions & 1 deletion src/R3.Avalonia/AvaloniaProviderInitializer.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
using Avalonia.Threading;
using Avalonia.Logging;
using Avalonia.Threading;

namespace R3.Avalonia;

public static class AvaloniaProviderInitializer
{
public static void SetDefaultObservableSystem()
{
SetDefaultObservableSystem(ex => Logger.Sink?.Log(LogEventLevel.Error, "R3", null, "R3 Unhandled Exception {0}", ex));
}

public static void SetDefaultObservableSystem(Action<Exception> unhandledExceptionHandler)
{
ObservableSystem.RegisterUnhandledExceptionHandler(unhandledExceptionHandler);
Expand Down

0 comments on commit 97d9562

Please sign in to comment.