2

I set this NSAssert

NSAssert(isStillLoadingArgument== [[self class] stillLoading],@"Hmm.... we think isStill Loading is false or true and yet stillLoading is true");;

Here is the screenshot of where I ask this question: enter image description here

Then when assertion fail, the code break here:

enter image description here

Which is very annoying because I want to see the assertion break on the code I set up the assertion instead. So, how do I do so.

Ben answer unfortunately doesn't solve the issue: enter image description here

user4951
  • 32,206
  • 53
  • 172
  • 282
  • Ben's answer does solve the issue. In the second picture, the debugger has stopped at the assert, it's just a different assert to yours. – JeremyP Jun 06 '12 at 15:59
  • Which second pictures? No debugger stop at main. If you look at my last screenshot I am shwoing where the asssert is. THe debugger (the green arrow) is on main. – user4951 Jun 07 '12 at 02:00
  • The bottom picture. http://i.stack.imgur.com/fyIZI.jpg Both the code window and the console output indicate that the assert it has stopped at is a different one to your assert. – JeremyP Jun 07 '12 at 09:37

2 Answers2

8

You need to add a Breakpoint to your project for all exceptions.

1) Click on breakpoint navigator

Breakpoint

2) Add an exception breakpoint

Exception

3) Make sure you set it to break on all exceptions

All

Now XCode will break to the actual assert rather than main. Hope this helps!

Ben Trengrove
  • 8,191
  • 3
  • 40
  • 58
  • Good answer, nice pictures :) – Aidan Steele Jun 01 '12 at 07:01
  • I tried that it still break on main. So why do we break on Throw? Also what do options automatically continue after evaluating will do? – user4951 Jun 05 '12 at 07:53
  • You can add actions to perform when the breakpoint is hit. Handy for when you just want the breakpoint to log something and then continue on without actually stopping. As for on throw, you want to break as soon as the exception is thrown. It is strange this didn't work for you, perhaps your assert is firing where you cannot actually see the assert like in apple classes. – Ben Trengrove Jun 05 '12 at 10:52
  • 1
    @JimThio you do realise don't you that Ben's answer is working perfectly? The debugger is breaking correctly on the `NSAssert` but it is a **different** assert to yours. – JeremyP Jun 06 '12 at 15:57
  • The green dot is at main. Sometimes NSAssert break at it's location. Most of the time it breaks at main. – user4951 Jun 07 '12 at 02:01
2

Configure the debugger to break on exceptions.

When an assertion fails, it raises an exception. If nothing catches the exception, it terminates the program after unwinding the stack, leaving it at main().

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • including exception that's catched? I don't want the program to break on catched exception. – user4951 Jun 02 '12 at 14:50
  • I never use try catch anyway just want to make sure. – user4951 Jun 02 '12 at 14:50
  • Yes, exception breakpoints will stop on exceptions that will be caught. Of course, breakpoints are only active when you're debugging. We're not talking about changing the behavior of your program. And you can just click the Continue button to let the program continue. Also, in Cocoa, exceptions should only be used for program errors that you should fix during development, so you should want to stop on exceptions even if they would be caught. – Ken Thomases Jun 02 '12 at 15:02
  • That's fine. I want to stop exception. I want to stop that at exceptions point. Not at main. – user4951 Jun 07 '12 at 02:01