Throwing NSException from IntPtr

I refer to the 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 something like this?

 NSException exception = (NSException)ObjCRuntime.Runtime.GetNSObject(handle); 
0
source share
2 answers

You yourself have found the correct answer:

 NSException exception = (NSException) ObjCRuntime.Runtime.GetNSObject (handle); 
+1
source

One option is to create a custom subclass of NSException and set up a protected constructor. Your ObjCRuntime.Runtime.GetNSObject should work too (I think not 100% sure).

You can create a really simple subclass as follows:

 public MyNSException : NSException { public MyNSException(IntPtr handle) : base(handle) { } } 

And then you will need to create your NSException as follows:

 var exception = new MyNSException(exception); 

I have not tried to use any of this code, but this should make you compile.

+1
source

All Articles