问题
I referring to this post:
private static void MyUncaughtExceptionHandler(IntPtr exception)
{
// this is not working because NSException(IntPtr) is a protected constructor
var e = new NSException(exception);
// ...
}
How can I create an exception here?
Should I do somehting like this?
NSException exception = (NSException)ObjCRuntime.Runtime.GetNSObject(handle);
回答1:
You found the correct answer yourself:
NSException exception = (NSException) ObjCRuntime.Runtime.GetNSObject (handle);
回答2:
One option is to create a custom subclass of NSException
and expose the protected constructor. Your ObjCRuntime.Runtime.GetNSObject
should also work (I think - not 100% sure).
You can create a really simple subclass like this:
public MyNSException : NSException {
public MyNSException(IntPtr handle) : base(handle) { }
}
And then you should be able to create your NSException
like so:
var exception = new MyNSException(exception);
I haven't tried using any of this code, but this should get you compiling.
来源:https://stackoverflow.com/questions/37525472/create-nsexception-from-intptr