question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What should I do with the global exception?

See original GitHub issue

Whether there is a mechanism like wfp’s DispatcherUnhandledException, my logic is that Project A refers to Project B, project B throws an exception, but not fatally just a hint. I want the program to continue running instead of exiting the program.

//when exception was throw
private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
    if (e.Exception is UserFriendlyException)
    {
        e.Handled = true;
        Log.Logger.Error(e.Exception.Message);
        MessageBox(e.Exception.Message);
        //Other logic...
    }
    //Other logic...
}

Any suggestions or best practices?

I still don’t find useful information through search engines, which is the only relevant introduction I’ve found so far, but I don’t quite understand how to use this https://gitter.im/AvaloniaUI/Avalonia?at=5d833ca2a7a5cc473319c6ed https://www.reactiveui.net/docs/handbook/default-exception-handler/

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

6reactions
worldbeatercommented, Jan 15, 2021

RxApp.DefaultExceptionHandler allows you to catch any exceptions thrown from a ReactiveCommand, ObservableAsPropertyHelper, and other stuff. It is recommended that in an Avalonia.ReactiveUI app you wrap the code that might throw exceptions into reactive commands (ReactiveUI ICommand implementation), see https://www.reactiveui.net/docs/handbook/commands/ This way your exceptions will tick through your RxApp.DefaultExceptionHandler and won’t cause the crash of your app.

// Here we subscribe to ReactiveUI default exception handler to avoid app
// termination in case if we do something wrong in our view models. See:
// https://www.reactiveui.net/docs/handbook/default-exception-handler/
//
// In case if you are using another MV* framework, please refer to its 
// documentation explaining global exception handling.
RxApp.DefaultExceptionHandler = Observer.Create<Exception>(Console.WriteLine);
4reactions
maxkatz6commented, Nov 2, 2021

@olgaMuravjova since DispatcherUnhandledException or any other global unhandled exception handling, which prevents app from crashing, (and most possibly being trapped in invalid state) is considered as a bad practice, we don’t really plan to support it.

If you want to handle global errors, you can catch them in Program.Main method, log and close the app peacefully (restart or open report-error app if needed). Any other expected errors should be handled explicitly in place where they are expected.

Alternatively, as it was mentioned above, if you are using ReactiveUI with your app, this library actually provides DefaultExceptionHandler for exceptions inside of observables. Though in most cases it means that Observable pipeline now in error state and won’t work anymore.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java Global Exception Handler
Learn how to globally handle all uncaught exceptions in your Java application.
Read more >
Spring Boot Global Exception Handling
Spring boot provides classes such as ResponseEntity and HttpResponse which are used to set the response codes and can send the exception entity...
Read more >
Spring Boot Global Exception Handler Examples
In exception handler methods, you can log the exception, redirect to user-friendly error pages, modify the response status code, ...
Read more >
Is it good to use a "global" try catch exception handler in ...
Yes, add a global exception handler so exceptions can be logged, but don't use it to let the application stay alive.
Read more >
Global Exception Handling in .NET 6
Global exception handling allows us to organize all exception handling logic in one place. Thus, we can improve the readability of the action ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found