Exception with insertObject: atIndex: on iOS6

I get the following exception on iOS6 (in an application with CoreData):

"2012-10-15 10: 21: 28.952 MyApp [68650: c07] * Application termination due to the uncaught exception" NSInvalidArgumentException ", reason:" * - [__ NSArrayM insertObject: atIndex:]: the object cannot be nil '* The first roll call stack: (0x28e6012 0x2659e7e 0x2899b6a 0x2899a20 0x1646941 0x1642c67 0x164f846 0x164f908 0x6c540 0x2057e83 0x28a5376 0x28a4e06 0x288ca82 0x288bf44 0x288be1b 0x33967e3 0x3396668 0x15a165c 0x13a22 0x2845) libS ++ abi.dylib: terminate called throwing exception "

This does not happen on iOS5, so something happens on iOS6, which I don’t understand. I set a breakpoint at every point where I call insertObject: atIndex: but they are not being called - it must be something in this libC ++ abi.dylib, which is called and called. Does anyone know what could be wrong?

Thank you

+4
source share
2 answers

The reason for the failure is that the object you are trying to insert is nil . This means that it is not created properly. This, in turn, means that something went wrong. before , you have reached this exception.

Could you please send the code that alloc ed and init initialized the object you were trying to insert?

To find the appropriate line of code, try the following: go to the Exception tab in your Xcode project:

Exception tab

Then click the "+" button (at the bottom of the page) and select "Add Exception ...". Leave all the default settings and click Finish.

If you re-run the project, it must stop in the corresponding line of code before the exception is thrown. You can then move the call stack and determine where in your code you named the library function that is responsible for this behavior. Then try to check if all objects at this point are correctly initialized.

+15
source

This is probably due to the fact that either iOS5 did not throw an exception for this error (and should be, but now iOS6 throws one that is better than it has erratic behavior later), or because you have other behavior in iOS6 that makes your object nil while it was not in iOS5.

For any reason, you can add a Symbolic breakpoint to the insertObject:atIndex: symbol so that it is interrupted 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 the + button to add a symbolic breakpoint. Add symbolic breakpoint
  • Set a symbolic breakpoint to break when it hits the [NSArray insertObject:atIndex:] Edit Symbolic Breakpoint

That way, you can see when this is called using the nil value for the first parameter and fix your problem where this happens.

Instead, you can add a Breakpoint Exception to break when an exception occurs, thereby knowing when your exception occurs in the code. This is another way to tell you which part of the code (your own or the other) throws an exception.

Exception breakpoint

Once the breakpoint has been deleted and the program will stop before an exception occurs, you can check the call stack for how much of your own code caused this exception to be triggered at the end.

+17
source

Source: https://habr.com/ru/post/1439759/


All Articles