Debugging Tip – objc_exception_throw breakpoint

If an exception is thrown when debugging an iPhone app, without your own exception handling code, that exception won't stop the debugger until the call stack has totally unwound. On that journey through the call stack it gets caught and disguarded in the event loop. That's a bummer because then the debugger can't show you where original exception was raised. This problem is easy to fix by adding a symbolic breakpoint for the runtime's objc_exception_throw function, which is called as soon as the exception occurs. Here's how: 1) Run the app in the debugger. There's an exception we can see in the debugger console:

screen 2

2) Open the debugger from XCode menu Run->Debugger. The stack we can see where the debugger paused is the useless stack where the event loop code caught the exception and then bombed out with its own exception.

screen 4

3) From XCode menu Run->Manage Breakpoints -> Add symbolic breakpoint we add 'objc_exception_throw'

screen 12

4) Now when we debug run again, the debugger stops as soon as the oringinal exception was thrown, we can see exactly where, and we can poke around an inspect variables etc.

screen 11