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 {
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
[FlurryAnalytics startSession:@" "];
....
}
You add a try-catch handler around the code that (might) throw NSExceptions:
MonoTouch already installs an uncaught exception handler, and automatically translates those ObjectiveC exceptions to managed exceptions.
This does the job. Call the SetupExceptionHandling() method on app launch. The magic is the NSRunLoop part. But the app is going to be in a weird state at that point, with unpredictable effects. Therefore, I would strongly suggest killing the app after the user decides what to do with the exception -- for example, by re-throwing it.