3

I need to catch ALL exceptions and errors in an iphone app. Obviously, this is only for really strange cases where the exception or error is totally unexpected. In those cases, it would be nice to log the error or something, so as to get knowledge of the issue and fix it in the future.

Do you know a way to catching ALL exceptions or errors that might have slipped from more specific handlers?

Thanks!

Manuel Araoz
  • 15,962
  • 24
  • 71
  • 95
  • an extension to my question: if possible, the method should catch all errors and exceptions on all threads! Thanks! :) – Manuel Araoz Jun 28 '10 at 14:41
  • 1
    possible duplicate of [How do I catch global exceptions?](http://stackoverflow.com/questions/2826351/how-do-i-catch-global-exceptions) – pgb Jun 28 '10 at 14:50

1 Answers1

10

In your app delegate put this function (note it's not a method, it's a standalone function):

// global uncaught exception handler
void uncaughtExceptionHandler(NSException *exception) {
    [FlurryAPI logError:@"Uncaught" message:@"Crash!" exception:exception];
}

And at the top of your applicationDidFinishLaunching*:

    // uncaught exceptions
    NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
ZaBlanc
  • 4,679
  • 1
  • 35
  • 38