【问题标题】:how to catch Terminating app due to uncaught exception: NSArrayM objectAtIndex index 0 beyond bounds for empty array如何捕获由于未捕获的异常而终止的应用程序:NSArrayM objectAtIndex index 0 beyond bounds for empty array
【发布时间】:2015-03-26 08:17:58
【问题描述】:
    *** 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

【问题讨论】:

  • 尝试使用异常断点。它将查明导致崩溃的代码行。 developer.apple.com/library/ios/recipes/…
  • @ZeMoon 我在许多循环中有数千个objectAtIndex,我认为它甚至不会在 UITableView 的源文件中崩溃,所以我无法下断点。它有时会崩溃,有时还可以。
  • ZeMoon 建议您设置一种特殊的断点——所有异常。它会在异常发生之前停止执行,并向您显示导致异常的代码行,因此您无需遍历千次停止。
  • 谢谢大家。我已经通过你的解决方案解决了! stackoverflow.com/questions/19095150/…
  • 或者如果您的应用程序已经在应用商店中,您可以使用第三方库来帮助您捕捉崩溃。例如试飞或崩溃分析

标签: ios objective-c uitableview


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多