Xamarin.Mac Managed UI Exception Handler

AndrewYoungAndrewYoung CAMember ✭✭

We're having figuring out how to add a decent managed UI exception handler to our Xamarin.Mac application.

On Windows, we use System.Windows.Forms.Application.ThreadException. This allows us to display a custom error dialog and provide an option to "continue" in an unknown state (allowing the user to attempt to save, etc).

Most of the answers I found suggest handling AppDomain.Current.UnhandledException on Mac. We handle this on Windows as well, as a backup plan, but it is a poor replacement for ThreadException because the application cannot recover, and on Mac, it seems the event loop has already quit when the event is raised which prevents us from even showing our custom error dialog.

Before Xamarin.Mac, we used an in-house Objective-C-to-C# bridge, and our bridge generated try...catch blocks around every Objective-C thunk so that all managed exceptions where caught before transitioning back into unmanaged code, and raised through an NSObject.UnhandledException event. This gave us practically the same error handling capabilities as we had on Windows.

How can we achieve the same with Xamarin.Mac?

Sign In or Register to comment.