11
Feb
09

iPhone development – tracking down uncaught exceptions

In the iPhone work I’ve been doing (my app), I’ve seen one error a number of times.. with various causes that were hard to track down. I’d see TERMINATED_DUE_TO_UNCAUGHT_EXCEPTION and never got a good stack trace. I found the solution in an iPhone dev forum (here) and thought I’d write this up to share the answer in case it saves someone some time.

What you need to do is set a breakpoint in objc_throw_exception. To do that, create a .gdbinit file in your home directory. Add the following to that file (I think the last line is the most important, but I have all of this in mine).

fb -[NSException raise]
fb -[_NSZombie release]
fb szone_error
fb objc_exception_throw

Then, bring up the debugger and run your app. Once you get an exception raised, the debugger stops where that exception is about to be thrown and you can see exactly where, in your code the problem originated! Big help to me, I can tell you! (Thanks, PhoneyDeveloper@iphonedevsdk.com!)


3 Responses to “iPhone development – tracking down uncaught exceptions”


  1. 1 matt
    June 12, 2009 at 4:20 am

    awesome, thanks!

  2. March 17, 2010 at 6:15 am

    Awesome thanks. Been missing the nice stack traces coming from Ruby on Rails.

  3. 3 AVEbrahimi
    April 19, 2010 at 7:38 am

    Really works, would be grate if works!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


SocialVibe


More frequent updates from me

Blog Stats

  • 93,881

The Author


Follow

Get every new post delivered to your Inbox.