Xcode 4 exception breakpoint

Did you ever have Objective-C code that would fail with an exception (such as asking for an objectAtIndex beyond the bounds of the array), but by the time you got word of it, all the stack trace had in it was the obj_msgsend and main? Yeah, I hate that.

Well I discovered that you can add a breakpoint to your project that will immediately break when the exception happens. To do this with Xcode 4, click on the Breakpoints symbol (2nd from the right) in the Navigator pane, click the + button at the bottom of the pane, and select Add Exception Breakpoint. From the bubble that appears, I selected Objective-C from the Exception choice (although I suspect you can safely leave it at all if you desire), and I left the Break selection at On Throw. Once you click Done, you should then have a new exceptions breakpoint in the list.

This was instrumental in helping me track down an issue on an app rescue that I am currently working on.

By the way, here is an awesome line of code that I found in the aforementioned app rescue. My brain hurts from looking at the code for long stretches of time, but there are some nice nuggets like this sprinkled in the code:

Assets *ass = [[Assets alloc]init];


  1. eugene says:

    thanks, helped me

  2. josh says:

    thanks, helped me, too. nice nuggets

  3. Mike C says:

    Thank you! I was wondering how to set an exception breakpoint. It’s pretty well hidden.

  4. Paul says:

    Thanks! I was looking for that!

Leave a Reply