Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
294 views
in Technique[技术] by (71.8m points)

ios - Exception with insertObject:atIndex: on iOS6

I'm getting the following Exception on iOS6 (on an App with CoreData):

"2012-10-15 10:21:28.952 MyApp[68650:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM insertObject:atIndex:]: object cannot be nil' * First throw call stack: (0x28e6012 0x2659e7e 0x2899b6a 0x2899a20 0x1646941 0x1642c67 0x164f846 0x164f908 0x6c540 0x2057e83 0x28a5376 0x28a4e06 0x288ca82 0x288bf44 0x288be1b 0x33967e3 0x3396668 0x15a165c 0x13a22 0x2845) libc++abi.dylib: terminate called throwing an exception"

This doesn't happen on iOS5, so something happens on iOS6 what I don't understand. I set a Breakpoint on every point where I call insertObject:atIndex: but these are not called - it have to be something in this libc++abi.dylib which gets called and crashes. Does anyone know what could be wrong?

thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is probably because either iOS5 did not throw an exception for this error (and should have, but now iOS6 throws one which is better than having erratic behavior later), or because you have some different behavior in iOS6 which makes your object nil whereas it was not in iOS5.

Whatever the reason, you can add a Symbolic Breakpoint on the insertObject:atIndex: symbol, so that it will break every time this method is called, wherever it is in your application (in your own code or not).

  • Go to the "Breakpoints Navigator" view (Cmd-6 shortcut)
  • Click on the "+" button to add a symbolic breakpoint Add symbolic breakpoint
  • Set the symbolic breakpoint to break when it hits the symbol [NSArray insertObject:atIndex:] Edit Symbolic Breakpoint

Thus you can see when this is called with a nil value for the first parameter and fix your problem where it occurs.

You can also instead add an Exception Breakpoint to break when an exception is thrown, thus knowing when in the code your exception occurs. This is another way to let you know which part of the code (your own or another) generate the exception.

Exception Breakpoint

Once the breakpoint has been hit and the program stops before the exception occurs, you can check in the call stack what part of your own code led to trigger this exception at the end.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...