Using objective-c exceptions in Xamarin.iOS

jayrlswjayrlsw USMember ✭✭


I am trying to use a private third-party objective-c library. It has its own exceptions, and each exception comes with extra data. In particular, the library's exception (let's call it MySDKException) contains a value called "errorCode" which would be very useful in debugging as well as displaying useful error messages as per the library's documentation.

I have created bindings for the library. The exception binds to an "NSException" which can not be used in a C# try/catch block as it is not derived from System.Exception. However, I am able to catch the error using a "MonoTouchException". I can't find a way to get MySDKException's error code from the MonoTouchException.

Running the code that causes the exception uncatched gives me the following:
Error code: Foundation.MonoTouchException: Objective-C exception thrown. Name: MySDKException Reason:
As well as a large native stack trace.

Is there any way to get MySDKException from MonoTouchException? Or at least, the data from the MySDKException (error code)?



Sign In or Register to comment.