Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSSetUncaughtExceptionHandler not catch all errors on iPhone

I'm using GTMStackTrace from http://code.google.com/p/google-toolbox-for-mac.

I need a way to test end-user to send me errors when the app crash. I know how send data to my website but the problem is how catch all non-handled errors.

I have this code:

void exceptionHandler(NSException *exception) {
    NSLog(@"%@", [exception reason]);
    NSLog(@"%@", [exception userInfo]);
    NSLog(@"%@", GTMStackTraceFromException(exception));

    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:NSLocalizedString(@"Error unexpected",@"Info: Can't save record")
                          message:GTMStackTraceFromException(exception) delegate:nil 
                          cancelButtonTitle:NSLocalizedString(@"Ok",@"Button: Ok") otherButtonTitles:nil];
    [alert show];
    [alert release];    
}

int main(int argc, char *argv[]) {
    //For crash report..
    NSSetUncaughtExceptionHandler(&exceptionHandler);
    //Normal code...
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

However, the thing not caught a lot of errors, like a bad release, a BAD ACCES, etc, and the App disappear. I have 2 issues where is not clear why happend and the end-users have not clue about what to say.

(For example release twice the same var is not catch)

So, how I get ALL that pesky errors so the end-user simple send me a crash report?

like image 451
mamcx Avatar asked Jul 14 '09 22:07

mamcx


2 Answers

EXC_BAD_ACCESS doesn't generate an exception, it generates a signal (SIGSEGV). To catch it, you need a signal handler. Christopher Atlan wrote a nice explanation of how to handle both kinds of crashes. Be sure to read both part 1 and part 2.

like image 58
Rob Napier Avatar answered Nov 10 '22 05:11

Rob Napier


if anyone is still dealing with this problem and can't work it out even with SIGSEGV see my post ... EXC_BAD_ACCESS automatic handling

like image 33
animal_chin Avatar answered Nov 10 '22 03:11

animal_chin