0

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);
Community
  • 1
  • 1
testing
  • 19,681
  • 50
  • 236
  • 417

2 Answers2

1

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.

dylansturg
  • 1,698
  • 15
  • 17
1

You found the correct answer yourself:

NSException exception = (NSException) ObjCRuntime.Runtime.GetNSObject (handle);
Rolf Bjarne Kvinge
  • 19,253
  • 2
  • 42
  • 86