MonoTouch:uncaughtExceptionHandler? [英] MonoTouch: uncaughtExceptionHandler?

查看:115
本文介绍了MonoTouch:uncaughtExceptionHandler?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In MonoTouch, how do I register an uncaught exception handler (or similar function)

在Obj-C中:

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

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


推荐答案

你可以在(可能)抛出NSExceptions的代码中添加一个try-catch处理程序:

You add a try-catch handler around the code that (might) throw NSExceptions:

try {
    FlurryAnalytics.StartSession (" ");
} catch (MonoTouchException ex) {
    Console.WriteLine ("Could not start flurry analytics: {0}", ex.Message);
}

MonoTouch已经安装了一个未捕获的异常处理程序,并自动将这些ObjectiveC异常翻译成管理例外。

MonoTouch already installs an uncaught exception handler, and automatically translates those ObjectiveC exceptions to managed exceptions.

这篇关于MonoTouch:uncaughtExceptionHandler?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆