NSRangeException:调用堆栈未显示行号

发布于 2024-12-17 09:11:15 字数 1439 浏览 1 评论 0原文

我收到以下索引越界错误:

*** 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)

我确切地知道该错误的含义,但我发现这些错误很难修复,因为由于某种原因,调用堆栈没有告诉我调用数组的代码行。这是线程 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

正如您所看到的,这个调用堆栈不是很有帮助,因为它没有显示我的代码中的任何方法。此外,错误中显示的调用堆栈有 22 个内存地址,而线程 1 的堆栈只有 15 个,而且地址根本不匹配。其他线程似乎没有包含任何有用的信息。

如何从错误中看到“第一个抛出调用堆栈”的线程(具有 22 个地址的线程),以便我可以找到导致此错误的行?也许我在“构建设置”中设置了错误的内容,导致相关堆栈无法检索?

如果有人能在这方面为我指明正确的方向,我将不胜感激。尝试手动定位有问题的线路是相当乏味的。

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

似最初 2024-12-24 09:11:15

打开调试器并在引发异常时设置断点,这样您就可以准确地知道哪一行代码是混蛋。

objc_exception_throw

或者,[NSException raise];

看一下以下问题:向 objc-exception 添加断点-抛出

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

挽容 2024-12-24 09:11:15

您在项目中启用了全局断点吗?
如果没有将 objc_exception_throw 添加到项目导航器中的断点部分,然后重新运行应用程序,您应该获得堆栈。此外,当发生崩溃时,观察并展开任何其他线程以查看它们的堆栈。我多次遇到过,我正在搜索的堆栈位于后台线程中,尽管主线程正在报告崩溃。 HTH。

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.

我偏爱纯白色 2024-12-24 09:11:15

假设这发生在 XCode 调试器中,您可以确定
回溯地址中引用的代码行。
在调试窗口中,输入以下内容:

list *address from traceback

例如,对于第一个条目,您将输入以下内容:
list *0x2263052

对每个地址执行此操作。其中之一应该指向您的程序代码
并列出失败的行号以及失败行上方和下方的代码。

-史蒂夫

Assuming this happened while in the XCode debugger, you can determine
the line of code referenced in the traceback addresses.
In the debug window, enter the following:

list *address from traceback

For example, for your first entry, you would enter the following:
list *0x2263052

Do this for each address. One of them should point to your programs code
and list the failing line number and code above and below the failing line.

-Steve

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文