c# - 单点触控 : uncaughtExceptionHandler?

标签 c# exception-handling xamarin.ios

在 MonoTouch 中,如何注册未捕获的异常处理程序(或类似函数)

在 Obj-C 中:

void uncaughtExceptionHandler(NSException *exception) {
      [FlurryAnalytics logError:@"Uncaught" message:@"Crash!" exception:exception];
  }

- (void)applicationDidFinishLaunching:(UIApplication *)application { 
     NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
     [FlurryAnalytics startSession:@" "];
    ....
}

最佳答案

    public delegate void NSUncaughtExceptionHandler(IntPtr exception);

    [DllImport("/System/Library/Frameworks/Foundation.framework/Foundation")]
    private static extern void NSSetUncaughtExceptionHandler(IntPtr handler);

    // This is the main entry point of the application.
    private static void Main(string[] args)
    {
            NSSetUncaughtExceptionHandler(
                Marshal.GetFunctionPointerForDelegate(new NSUncaughtExceptionHandler(MyUncaughtExceptionHandler)));

            ...
    }

    [MonoPInvokeCallback(typeof(NSUncaughtExceptionHandler))]
    private static void MyUncaughtExceptionHandler(IntPtr exception)
    {
        var e = new NSException(exception);
        ...
    }

关于c# - 单点触控 : uncaughtExceptionHandler?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9491813/

相关文章:

C#读取所有字节

c++ - 捕获未知异常

ios - iOS 上的 Skype for Business 应用程序 SDK - 为什么 SfBApplication.sharedApplication 返回 nil/null?

c# - Windows Azure - approot 路径中的访问被拒绝

c# - w3wp.exe 如何与 Web 应用程序一起工作?

java - SAX异常 : Content is not allowed in trailing section

xamarin.ios - 绑定(bind)到自定义.framework

xamarin.ios - 我如何在 Xamarin 上画圆圈?

c# - 使用存储库时,ASP.NET MVC 中业务逻辑的最佳位置是什么?

c# - 如何在不重置堆栈跟踪的情况下抛出异常?