Dealing with TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION

During debugging I have seen seen TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION thousands of times which resulted in  me wasting all kinds of time stepping through my code or putting in hundreds of NSLog statements to figure out where in my code the “uncaught exceptions” are happening.

From my work on other platforms, their debug environments did a much better job at showing where the exception is being thrown.

I finally did some research and found the answer.

Before…

before stack trace

It tells you nothing about where your app is crashing.

What you need to do is a add an objc_exception_throw breakpoint to your global breakpoints.

In Xcode go to Run > Show > Breakpoints menu.

Then Double-Click for Symbol.

Paste in objc_exception_throw

It will look like this:

breakpoints window

Now run your program again in Debug mode (cmd-Y) and you will see this…

break on objc_exception_throw

And you can quickly track down where your app is crashing.

The is supposed to be a way to edit the ~/.gdbinit file and put a “b objc_excpetion_throw” command into it so you don’t have to add it yourself, but I’m still trying to figure out how to make that work.*

*A solution to Global Breakpoint from Lou Krieg: ”I discovered that if you set that breakpoint as your blog says, then in the Groups & Files browser, expand Breakpoints, and drag that breakpoint from Project Breakpoints to Global Breakpoints a copy is made, and it seems to stick across projects”

Let us know what you think!

Catamount Software is proudly powered by WordPress and is lovingly designed by I.M.A.G.E
Entries (RSS) and Comments (RSS).