Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to track down the line that's causing a runtime error?

My app is crashing with this error message:

'NSInvalidArgumentException', reason: '-[__NSCFDictionary setObject:forKey:]: attempt to insert nil value (key: 0)'

and I am trying to find where this is occuring in my code. I have set NSZombiesEnabled in the environment variables, however it's pretty hard to figure out the location. Any idea on how to debug?

I typed in bt and here's what I see:

 frame #0: 0x30d1832c libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x3597d20e libsystem_c.dylib`pthread_kill + 54
    frame #2: 0x3597629e libsystem_c.dylib`abort + 94
    frame #3: 0x35055f6a libc++abi.dylib`abort_message + 46
    frame #4: 0x3505334c libc++abi.dylib`_ZL17default_terminatev + 24
    frame #5: 0x36c38356 libobjc.A.dylib`_objc_terminate + 146
    frame #6: 0x350533c4 libc++abi.dylib`_ZL19safe_handler_callerPFvvE + 76
    frame #7: 0x35053450 libc++abi.dylib`std::terminate() + 20
    frame #8: 0x35054824 libc++abi.dylib`__cxa_rethrow + 88
    frame #9: 0x36c382a8 libobjc.A.dylib`objc_exception_rethrow + 12
    frame #10: 0x3428d50c CoreFoundation`CFRunLoopRunSpecific + 404
    frame #11: 0x3428d36c CoreFoundation`CFRunLoopRunInMode + 104
    frame #12: 0x3826f438 GraphicsServices`GSEventRunModal + 136
    frame #13: 0x36d27cd4 UIKit`UIApplicationMain + 1080
    frame #14: 0x00051cdc AppName`main + 80 at main.m:16
like image 302
adit Avatar asked May 14 '12 00:05

adit


1 Answers

Add exceptions as a breakpoint. Assuming Xcode 4+...

  1. At the top of the navigator frame (where you view files and such), you will see a little icon that looks like a sideways arrow.
  2. That will show the breakpoint navigator. At the bottom of that view, click the + to add a breakpoint.
  3. Click on "Add exception breakpoint..."

The default option is probably fine... you want to break on throw of all exceptions.

Now, when you run, you will get a breakpoint anywhere your app throws an exception.

like image 108
Jody Hagins Avatar answered Oct 19 '22 06:10

Jody Hagins