Pages

Friday, March 9, 2012

Missing stack trace in Xcode 4.2+ on iOS Device and Simulator when exception is thrown

After updating Xcode to version 4.2 I had difficulties with iOS app debugging.
For example, when I call objectAtIndex: method of an empty NSArray object, my app receives SIGABRT signal and execution is stopped in main() function with no information that can help me to find the error:

NSRangeException will be thrown

In console we can see that our app has terminated due to uncaught exception NSRangeException.
So the problem is that Xcode doesn't setup exception handler.

Xcode allows us add exception breakpoints. Open Breakpoint Navigator and click "+" in bottom left of this tab:

Then click "Add Exception Breakpoint...". You will see next window:


After clicking "Done" try to run your app. You will see that execution is stopped on line of code where exception is thrown with full stack trace:
Also Xcode allows us to share any breakpoint with all your projects. When you Right-click (or Ctrl-Click) on breakpoint and choose "Move Breakpoint To"->"User" you will move the breakpoint to your user profile.

Now it's much more easier to debug any iOS app in Xcode. 

No comments:

Post a Comment