Select Page

template-blog-topTracing exceptions is always a he** of a fun, so descriptive sometimes:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x1e6f012 0x1b7ce7e 0x1e110b4 0x585f2 0xba5817 0xba5882 0x9d61 0xba5648 0xba5882 0xba5b2a 0xbbcef5 0xbbcfdb 0xbbd286 0xbbd381 0xbbdeab 0xbbe4a3 0xbbe098 0xa4f3 0x1b90705 0xac7920 0xd03b24 0x1b90705 0xac7920 0xac78b8 0xb88671 0xb88bcf 0xb87d38 0xaf733f 0xaf7552 0xad53aa 0xac6cf8 0x2e64df9 0x2e64ad0 0x1de4bf5 0x1de4962 0x1e15bb6 0x1e14f44 0x1e14e1b 0x2e637e3 0x2e63668 0xac465c 0x2ab1 0x2915)
libc++abi.dylib: terminate called throwing an exception

This is one kind of error that XCode can throw at us, and the exception stop point is the main.m file so, if the error is not related to a really unique feature of our code, we are in trouble, for sure.

To rescue us from a miserable debugging, XCode 4 comes with a very handy function: breakpoints. This is not new, you can set breakpoints and debug the exception manually, watching the section of the code affected or leave it all to the IDE. This method is sometimes unhelpful, because the error jumps at a lower level, or on the superclass, so the debugging becomes tricky. Though that, the debugging feature we want to enable is “Add exception breakpoint“, located on the breakpoints panel, on the left side of the window:

With this breakpoint enabled, any exception will stop at the exact point it’s generated, and it will allow us attack directly to the culprit. Sounds good, right?

XCode 4 is a great IDE for developing, not only Objective-C apps, but also C / C++, and it’s becoming more and more feature-rich one update after another. Additional modules, like iOS Simulator, Instruments, Interface Builder (now embedded into the main IDE) make your productivity grow up high every day.