Create NSException from IntPtr

我只是一个虾纸丫 提交于 2019-12-12 03:48:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!