Question

I have big project with async event, and sometimes i have error [__NSArrayM insertObject:atIndex:]: object cannot be nil, but I havent idea where is throwing this error.. How can I catch this error? I make assert in everywhere where I make operation insertobject:atIndex and nothing..

This is stack:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '***    -[__NSArrayM insertObject:atIndex:]: object cannot be nil'


*** First throw call stack:

(0x34c352a3 0x32f4597f 0x34b7f8d9 0xc48db 0xc3ced 0xc3b41 0x1178d9 0x148aed 0x103cfd    0x102fc9 0x101f95 0x35f25595 0x35f7a13b 0x35f7a081 0x35f79f65 0x35f79e89 0x35f795c9 0x35f794b1 0x35f67b93 0x35f67833 0xd820b 0x35fc8275 0x3604aea9 0x326efa6f 0x34c0a5df 0x34c0a291 0x34c08f01 0x34b7bebd 0x34b7bd49 0x350b82eb 0x35f5a301 0x62e45 0x62de0)

libc++abi.dylib: terminate called throwing an exception
Was it helpful?

Solution

A good way to check where your code is crashing is:

1) goTo the breakpoint tab in Xcode.

2) click on the '+" button at the bottom.

3) Add Exception Breakpoint

a) In the break tab select both:

  i) on Throw 

  ii) on Catch 

and build and r un.

4) These breakpoints will give you exactly where your app is crashing 90% of the times.

Hope this helps you in someway. :)

OTHER TIPS

Sometimes if you can not find the exception where its throwing. Just try adding these symbolic breakpoints in your project. Then run

 objc_exception_throw 
 malloc_error_break
 [NSException raise]

In your Xcode goto Product -> Debug -> Create Symbolic Breakpoint. Enter each breakpoint mentioned above in Symbol then press Done or you can alternatively create by going to the Breakpoint navigator (cmd + 6) in bottom left corner you can find + symbol, click that + then Add symbolic breakpoint . Now try to run, it'll get you to the specific line where its crashing.

Think you need to handle the null value from Array . Its working for me something like:

if ( array ! = nil ) {
    NSLog(@"name is nil");
} else {
    // addobject to array 
}

Apparently, the object you inserted should not be nil. Check it!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top