Debug Exception in Xcode

Sometimes it happens that Xcode throws you an exception, and you don’t know why. How do you print the relevant Exception information?

To get more information, you can configure the debugger to break when any exception is thrown. Go to the Breakpoint Navigator and click the little ‘+’-button at the bottom. Then click “Add Exception Breakpoint”.

Add Exception BreakpointBut, in many cases, even then you don’t get the information you wanted when the Exception occurs. Add these commands to the breakpoint configuration to show the name and reason of the breakpoint. This should get you on the way to eliminate the error.

Breakpoint on all exceptions

po [*(id *)($esp+4) name] and

po [*(id *)($esp+4) reason]

 

This works when you are using LLDB by printing the name and reason of the exception in the command window. You can also execute those commands in the command window, but you have to make sure to select stackframe 0 first.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.