Reputation: 1476
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?
Upvotes: 3
Views: 938
Reputation: 2678
turn on the xcode "hide or show the Debug area"
then from that menue select "Show only the Console" button
now when the error appears find the symbole (lldb) and type bt next to it
Upvotes: 0
Reputation: 1499
In the console, you can type "bt" for backtrace and you'll see the last calls. But for certain errors, it's not displayed so add an exception breakpoint as graver mentioned
Upvotes: 0
Reputation: 122391
You are generally given a symbolic stracktrace to figure out where exceptions originate. Other alternatives are setting-up your own exception handling and providing the symbolic stacktrace using backtrace
and friends (manpage) and when it comes to figuring out where crashes occur in production code, where symbols are generally stripped, there is the atos
utility (manpage).
Upvotes: 0
Reputation: 15213
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".
Upvotes: 4