Handle unhandled exception in MAUI

Dani_S 3,336 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,

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,231 questions
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 39,391 Reputation points Microsoft Vendor
    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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful