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
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!
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
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.
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