Avoid Mac app crash after unhandled exception

I want my application not to close after an unhandled exception has been processed.

I do this with Xamarin and MonoMac, but I think I could translate Objective-C answers into C #.

When an exception occurs and it is not caught anywhere, I log an event of unhandled exceptions:

AppDomain.CurrentDomain.UnhandledException += HandleUnhandledException;

And write it down:

static void HandleUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
    //Log the exception...
}

But then, when an exception occurs, a HandleUnhandledException is thrown and the event loop ends:

NSApplication.Main(args);

So my application is ending. How can i avoid this? Where should I place the try-catch block?

+4
source share
2 answers

Here's what the xamarin developer has to say:

" AppDomain.CurrentDomain.UnhandledException, , ( , , , , . , , ).

, -, yo catch try, , catch. , .

+3

, , , , - ... !... , AppDelegate.cs :

            AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => {
                Exception GivenException = (Exception) e.ExceptionObject;
                Console.WriteLine( GivenException.Message);
                Console.WriteLine( GivenException.StackTrace);
                Console.WriteLine("Runtime terminating: {0}", e.IsTerminating);
            };

, , , , .

0

Source: https://habr.com/ru/post/1542306/


All Articles