Set a Breakpoint on Unhandled Exceptions in the Xcode Debugger

This entry was posted by Tuesday, 16 August, 2011
Read the rest of this entry »

One of the most frustrating things in iOS development is when the Xcode debugger doesn’t break on unhandled exceptions.  On most other platforms I’ve developed, the debugger always stops on exceptions you didn’t specifically catch in your code.  For some reason, the Xcode debugger doesn’t.  I suspect it’s really more of a GDB problem when debugging Obcjective-C than an Xcode issue.  There is something you can do though.

By adding a couple of breakpoints, the debugger should stop when an unhandled exception is thrown.   Start by going to the Run | Show | Breakpoints menu.  First, create a symbolic breakpoint named “objc_exception_throw” in the Location “libobjc.A.dylib”.  The symbolic breakpoint is important, otherwise, the debugger won’t catch anything.

Then, create a 2nd breakpoint called “-[NSException raise]” in the Location “CoreFoundation”.  You should be all set!  Run your app, and viola!  If it throws an exception, you’ll be in the debugger with a nice, beautiful stack trace!

One final suggestion I’d make is to make them global breakpoints instead of project breakpoints.  By doing that, they will be set for all your apps from the beginning, saving you tons of time and frustration.

Did you like this article? Please share it:

One Response to “Set a Breakpoint on Unhandled Exceptions in the Xcode Debugger”

  1. Allen

    In the breakpoint Navigator, just click the + in the lower left corner, then select Add Exception Breakpoint and leave the default values (All, On Throw).