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:@" "];
....
}
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);
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With