Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App crashing....objc_exception_throw

My app keeps crashing at one point. It doesn't tell me why, the exception breakpoint happens at

return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

so I have no idea what's causing the crash. On left hand side, it tells me it was because of objc_expcetion_throw. How can I debug this? THanks

like image 716
0xSina Avatar asked Feb 29 '12 16:02

0xSina


3 Answers

In cases like this, I will create a break point that breaks on all exceptions. This is the default breakpoint that gets created if you just click the add button on the breakpoint tab.

With this breakpoint, XCode will stop at the point of the exception and I see the line of code where it happened along with the stack.

I would have posted an image of this but I do not have enough rep!

like image 73
Josh Laase Avatar answered Sep 20 '22 20:09

Josh Laase


Use a @try / @catch:

@try {
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
@catch (NSException *ex)
{
    // log ex...
}

Or you can use the uncaught exception handler:

void uncaughtException(NSException *except)
{
    // log Except
    NSLog(@"Exception!");
}

NSSetUncaughtExceptionHandler(uncaughtException);
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

Finally, you can always break on objc exceptions:

Product->debug->create symbolic breakpoint
Symbol: objc_exception_throw
like image 42
Richard J. Ross III Avatar answered Sep 23 '22 20:09

Richard J. Ross III


Follow Richard's advice and implement the uncaughtException handler. Set a breakpoint in the handler. When the exception fires, type this in your output console:

po [except callStackSymbols]

That should give you more details as to the origin of the exception.

Note: except is the name of the exception variable you used.

like image 24
Jeremy Avatar answered Sep 20 '22 20:09

Jeremy