Xcode exception breakpoint doesn't print details of the exception being thrown

IosObjective CXcode

Ios Problem Overview


SUMMARY

When I set an exception breakpoint, I don't get the exception message. How do I get the exception message? I already know how to get the stack trace, but that doesn't include the exception message.

DETAILS

In the past I developed iOS Apps with Xcode and when there was a problem, I'd get an error/exception. The exception would often have a message like "can't dereference null" or whatever.

Now, using Xcode 4.6.x for the past several weeks I've never gotten an exception message. I'll often get a SIGABRT. I put in the break on exception breakpoint and it will break there, but it's off in some assembly within the iOS SDK and I never get a message.

In fact, I can't remember the last time I saw anything show up in the debugger console.

Did exception info dissappear with the migration to LLVM?

It's very frustrating to have my app just crash in the SDK without knowing why. I check the last function to make sure things are set up correctly (objects allocated, etc) and they are which means I'm left with no clues.

Is it possibly a build setting held over from the past is somehow turning off exception messages?

Please reopen question. It now has an answer!

In the comments an excellent answer has been given. This should be promoted to full answer, and so I can mark the question answered and others who have this common issue can find it. In order for that to happen, the question needs to be reopened! (I'll delete this plea after that happens.)

Ios Solutions


Solution 1 - Ios

I will update Jeff's answer here:

> To have both the line causing the exception highlighted (and not UIApplicationMain() in main.m) AND to see the reason for the exception (e.g., "error: A fetch request must have an entity."), do this: >

  • In the Breakpoint navigator:
    1. Add (+), Add Exception Breakpoint
    2. Select the new breakpoint, Control-Click, Edit Breakpoint
    3. Add Action
    4. Enter: po $arg1

>The relevant part of the stack trace will be in the nagivator area.

This seems to still work in Xcode 9

Here is my addition for use with Xcode 6 and below.

  1. Enter: po (NSException) $eax*

In Xcode 6 you must explicitly provide the object type because it is no longer inferred.

Solution 2 - Ios

For Xcode 7-9 (based off Jeff's answer):

In the Breakpoint navigator:

  1. Add (+), Add Exception Breakpoint
  2. Select the new breakpoint, Control-Click, Edit Breakpoint
  3. Add Action
  4. Enter: po $arg1

Solution 3 - Ios

To have both the line causing the exception highlighted (and not UIApplicationMain() in main.m) AND to see the reason for the exception (e.g., "error: A fetch request must have an entity."), do this:

  • In the Breakpoint navigator:
    1. Add (+), Add Exception Breakpoint
    2. Select the new breakpoint, Contorl-Click, Edit Breakpoint
    3. Add Action
    4. Enter: po $eax

The relevant part of the stack trace will be in the nagivator area.

Solution 4 - Ios

Yes xcode is not so friendly for debugging. I like this article which helps me to understand crash logs a bit clearly)) Demystifying iOS Application Crash Logs

Also do this if you see error "message sent to deallocated instance"

'Products -> Edit Scheme -> Enable Zombie Objects'

this will enable zombie objects and when you do profile to your project choose "zombie", cause error and you will be able to see which objects was deallocated e.g NSArray *myArray

Solution 5 - Ios

The information I get from po $eax or po (NSException *)$eax seems to be different from what Xcode would print if no exception breakpoints are set. So I do the following,

  1. Add an exception breakpoint
  2. Exception occurs, breakpoint was hit -> I know the location
  3. Temporarily disable breakpoints (second button on the left in Debug area)
  4. Continue program execution (third button on the left in Debug area)
  5. Details are printed -> I know the cause

Obviously not very elegant and flexible, but at least I two big questions are answered (where and why).

Solution 6 - Ios

You can use bt or thread backtrace command to print error trace

>Show the stack backtrace for the current thread.

The same stack trace you can find in crash reports

enter image description here

Information about current thread use currentThread

//Objective-C
po [NSThread currentThread]

//Swift
po Thread.currentThread

*Sometimes you can use fr v(or just v from XCode 10.2) when po is not working

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnirvanaView Question on Stackoverflow
Solution 1 - IosucangetitView Answer on Stackoverflow
Solution 2 - IosjcadyView Answer on Stackoverflow
Solution 3 - IosJeffView Answer on Stackoverflow
Solution 4 - IosRomaView Answer on Stackoverflow
Solution 5 - IosbcauseView Answer on Stackoverflow
Solution 6 - IosyoAlex5View Answer on Stackoverflow