- 4 years ago 145
C# Question

MonoTouch: uncaughtExceptionHandler?

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

In Obj-C:

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

- (void)applicationDidFinishLaunching:(UIApplication *)application {
[FlurryAnalytics startSession:@" "];

Answer Source

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 already installs an uncaught exception handler, and automatically translates those ObjectiveC exceptions to managed exceptions.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download