Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the spot of NSInvalidArgumentException of NSArray?

Xcode is throwing exception:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM insertObject:atIndex:]: object cannot be nil'

However in debug mode it does not halt where the exception happened. It ends in

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

with message "SIGABRT". Stack trace only shows this "main".

Is there any way to figure out where in the code a nil object has been attempted to get inserted in an array?

like image 303
openfrog Avatar asked Dec 26 '12 20:12

openfrog


1 Answers

In your project, go to the Breakpoint navigator, click the [+] button and Add Exception Breakpoint.... Click Exception > All, and Break > On Throw, click [Done].

With this setting in place, Xcode should break at the place in your project where the exception is thrown. You may need to walk down the stack for a frame or two to get to your code.

like image 144
Sergey Kalinichenko Avatar answered Oct 20 '22 14:10

Sergey Kalinichenko