When an application throws an exception, there is debug information shown in the console – below is the output in the console for an NSInvalidArgumentException:
Although helpful, depending on the size of your application, it may take quite some time to find the offending code. One way to better track exceptions is to catch them, as shown in this post Try, Catch and Finally. However, wrapping every potential condition is not always practical. There is another way to track down exception errors.
With a symbolic breakpoint, we can force the runtime to stop on the line of code that is generating the exception. Select the breakpoint tab (in the Project navigator) and tap the + in the lower left corner to create a new symbolic breakpoint. Enter objc_exception_throw for the Symbol as shown below:
When you run the application with the symbolic breakpoint enabled, the code will stop at the offending line:
Notice in the console the reference to obj_exception_throw and Pending breakpoint – the debugger stops before the actual line of code executed.
When you experience an exception that is not wrapped in a try/catch block, give the symbolic breakpoint a go.