Handle unhandled exception in MAUI

Dani_S 4,501 Reputation points
2023-10-25T04:58:34.8066667+00:00

Hi,

I used .Net 7 , vs 17.4 in windows.

Is there place where i can treat unhandled exception in MAUI app like IN WPF ?

Thanks,

Developer technologies .NET .NET MAUI
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2023-10-27T06:34:40.0566667+00:00

    Hello,

    The four methods provided in this thread's answer are not WPF platform-specific APIs, and you can use them in MAUI with the following code.

    AppDomain.CurrentDomain.UnhandledException += (s, e) =>
     {
                    Console.WriteLine("AppDomain");
    };
    TaskScheduler.UnobservedTaskException += (s, e) =>
    {
                    Console.WriteLine("TaskScheduler");
    };
    Dispatcher.Dispatch(new Action(() => { Console.WriteLine("test"); }));
    Application.Current.Dispatcher.Dispatch(new Action(() => { Console.WriteLine("test"); }));
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    3 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.