Search code examples
iphoneiosxcodedebuggingios-simulator

How to figure out the `call stack` meaning in simulator?


I got an exception when I tried to put a nil object to a NSDictionary using the following code:

NSString * object = [self someMethod]; // the method return nil
NSDictionary * dict = @{ @"key": object };

This is a simple error I know, I just use it as an example. The app crash in simulator and the error message in console is below:

 2012-11-13 14:40:00.528 Ape[44456:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[2]'

 *** First throw call stack:
 (0x208b012 0x1a68e7e 0x2051a95 0x207e4e9 0x93f72 0x939b4 0x8800f 0x85f4d 0x852a3 0x1ce853f 0x1cfa014 0x1ce9fd6 0x1cfa014 0x1cf18b7 0x1ced405 0x1cea768 0x2031af5 0x2030#
 libc++abi.dylib: terminate called throwing an exception

My question is how to figure out the call stack message in console and find out which line of code cause the problem?


Solution

  • You need to add an exception breakpoint. Open Xcode -> Navigator -> Breakpoints (shortcut Cmd+6). In the lower left corner, there's a + sign, click it and select "Add exception breakpoint..." then "Done".