gpt4 book ai didi

ios - 由于未捕获的异常: NSArrayM objectAtIndex index 0 beyond bounds for empty array,如何捕获终止应用程序

转载 作者:行者123 更新时间:2023-12-01 18:53:45 24 4
gpt4 key购买 nike

    *** Terminating app due to uncaught exception 'NSRangeException', reason: '
*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x276b2fef 0x35ba6c8b 0x275c5841 0xe78bb 0xfe689 0x2b19e281 0x2b19ebab 0x2aedc981 0x2b19ea63 0x2b19f1b3 0x2afac2df 0x2b1943a7 0x2afa34d7 0x2aecd003 0x2a8eefc1 0x2a8ea7fd 0x2a8ea685 0x2a8ea031 0x2a8e9e1f 0x2a8e3b79 0x27678ffd 0x276766bb 0x27676ac3 0x275c3221 0x275c3033 0x2eff2201 0x2af2f8c9 0x114b59 0x36156aaf)
libc++abi.dylib: terminating with uncaught exception of type NSException

我有很多 [NSArray objectAtIndex] ,我不知道是哪一个让它崩溃了。
我已经编写了下面的调试代码,但仍然无法捕捉到它。它在 UITableView 中,我通过下拉表格加载越来越多的单元格,然后它有时会崩溃。
    #import "NSArray+Debug.h"
#import "MLTool.h"

@implementation NSArray (Debug)

- (id)objectAtIndexEx:(NSUInteger)index{
if (self.count<1) {
assert(0);
}

NSString *str=[NSString stringWithFormat:@"count=%d,index=%d,info=%@",self.count,index,[self objectAtIndex:index]];
if ([MLTool isEmptyString:str]
// ||str==
) {
assert(0);
}

NSLogUTF8(@"break:%@",str);
return [self objectAtIndex:index];
}
@end

最佳答案

您可以在 xcode 中添加一个“异常断点”,以在崩溃时停止调试并检查它为什么会崩溃。

为此,在左侧导航器的断点/调试部分中,您可以点击左下角的“+”以添加“异常断点”。

关于ios - 由于未捕获的异常: NSArrayM objectAtIndex index 0 beyond bounds for empty array,如何捕获终止应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29273763/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com