Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSRangeException: Call Stack Not Showing Line Number

I am getting the following index out of bounds error:

*** Terminating app due to uncaught exception 'NSRangeException', reason: 
'*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x2263052 0x24c7d0a 0x224fdb8 0x2f4a7 0x2264ec9 0x81e299 0x81e306 0x75aa30 
0x75ac56 0x741384 0x734aa9 0x39a9fa9 0x22371c5 0x219c022 0x219a90a 0x2199db4 
0x2199ccb 0x39a8879 0x39a893e 0x732a9b 0x1e5b 0x1dc5 0x1)

I know exactly what the error means, but I find these errors very difficult to fix because for some reason the call stack isn't telling me the line of code where the array was being called. Here is the call stack from thread 1:

#0  0x9706d9c6 in __pthread_kill ()
#1  0x93e2cf78 in pthread_kill ()
#2  0x93e1dbdd in abort ()
#3  0x02859e78 in dyld_stub__Unwind_DeleteException ()
#4  0x0285789e in default_terminate() ()
#5  0x024c7f4b in _objc_terminate ()
#6  0x028578de in safe_handler_caller(void (*)()) ()
#7  0x02857946 in __cxa_bad_typeid ()
#8  0x02858b3e in __cxa_current_exception_type ()
#9  0x024c7e49 in objc_exception_rethrow ()
#10 0x02199e10 in CFRunLoopRunSpecific ()
#11 0x02199ccb in CFRunLoopRunInMode ()
#12 0x039a8879 in GSEventRunModal ()
#13 0x039a893e in GSEventRun ()
#14 0x00732a9b in UIApplicationMain ()
#15 0x00001e5b in main

As you can see this call stack is not very helpful because it doesn't show any methods from my code. Also, the call stack shown in the error has 22 memory addresses, while the stack from thread 1 only has 15, and the addresses don't match at all. No other threads seem to contain any useful information.

How is it possible to see the thread of the "First throw call stack" from the error (the one with 22 addresses), so I can find the line causing this error? Perhaps I have something set incorrectly in my Build Settings that is causing the relevant stack to not be retrievable?

If someone could point me in the right direction on this I'd be very grateful. Trying to locate the offending line manually is quite tedious.

Thanks!

like image 407
llama591 Avatar asked Nov 23 '11 09:11

llama591


2 Answers

turn on the debugger and set a breakpoint on whenever an exception is thrown, this way you exactly know which line of code is being a jerk.

objc_exception_throw

Alternatively, [NSException raise];

Have a look at the following question: Add breakpoint to objc-exception-throw

like image 107
Antwan van Houdt Avatar answered Oct 29 '22 20:10

Antwan van Houdt


Did you enable global breakpoints in your project? if not add objc_exception_throw to the breakpoints section in the project navigator then re-run the app, you should get the stack. In adition, when you crash happends, watch and expand any additional threads to see their stacks as well. It happened to me several times that the stack i was searching was in a background thread, though the crash was being reported by the main thread. HTH.

like image 28
Vlad Avatar answered Oct 29 '22 19:10

Vlad