Some favorite site feeds aggregated locally: iPhone Development RSS   Adobe Labs RSS   Macrumors RSS

Thursday, May 28, 2009

Xcode: Uncaught exceptions with breakpoint!

Thursday, May 28, 2009    2 Comments

While developing for the Mac or the iPhone, you're going to bump heads with the TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION a bit. While this is nominally useful information, you never are told where the exception happened, only the reason that it did. If your application isn't very large in scope, this may be all the information you'll need to debug the problem. However, for larger applications this isn't the best.

One thing I just discovered is that you can have Xcode automagically place a breakpoint where the exception occurs, thus showing you just where the exception was thrown. Paired with the information on why, this is a big help in debugging.

To set this up, open up your Breakpoints window (in my version of Xcode I double-click on the Breakpoints items in the editor window Groups & Files tree control. You'll see a breakpoint item "Double-Click for Symbol" - set the breakpoint to "objc_exception_throw" and you're done. It should look something like this:
Now when you get an exception, you should be able to click the exposed line in the debugger stack trace which will take you to the offending line of code in your project.

Labels: , ,