Manuel Araoz
Manuel Araoz

Reputation: 16406

how do I catch all exceptions in iphone?

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!

Upvotes: 3

Views: 3880

Answers (1)

ZaBlanc
ZaBlanc

Reputation: 4718

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);

Upvotes: 10

Related Questions