【问题标题】:NSSetUncaughtExceptionHandler not catch all errors on iPhoneNSSetUncaughtExceptionHandler 无法捕获 iPhone 上的所有错误
【发布时间】:2010-11-10 20:12:37
【问题描述】:

我正在使用来自http://code.google.com/p/google-toolbox-for-mac 的 GTMStackTrace。

我需要一种方法来测试最终用户,以便在应用崩溃时向我发送错误消息。我知道如何将数据发送到我的网站,但问题是如何捕获所有未处理的错误。

我有这个代码:

void exceptionHandler(NSException *exception) {
    NSLog(@"%@", [exception reason]);
    NSLog(@"%@", [exception userInfo]);
    NSLog(@"%@", GTMStackTraceFromException(exception));

    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:NSLocalizedString(@"Error unexpected",@"Info: Can't save record")
                          message:GTMStackTraceFromException(exception) delegate:nil 
                          cancelButtonTitle:NSLocalizedString(@"Ok",@"Button: Ok") otherButtonTitles:nil];
    [alert show];
    [alert release];    
}

int main(int argc, char *argv[]) {
    //For crash report..
    NSSetUncaughtExceptionHandler(&exceptionHandler);
    //Normal code...
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

但是,这个东西并没有发现很多错误,比如发布错误、访问错误等,并且应用程序消失了。我有 2 个问题不清楚为什么会发生,最终用户也不知道该说什么。

(例如释放两次相同的 var 不捕获)

那么,我如何得到所有这些讨厌的错误,以便最终用户简单地向我发送崩溃报告?

【问题讨论】:

  • 另外,是否可以获得带有错误行的完整堆栈跟踪?
  • 你真的能让 UIAlertView 显示出来吗?我做不到。有什么建议吗?

标签: iphone error-handling crash


【解决方案1】:

EXC_BAD_ACCESS 不会产生异常,它会产生一个信号 (SIGSEGV)。要捕获它,您需要一个信号处理程序。 Christopher Atlan 写了一篇关于如何处理这两种崩溃的nice explanation。请务必阅读part 1part 2

【讨论】:

    【解决方案2】:

    如果有人仍在处理这个问题并且即使使用 SIGSEGV 也无法解决,请参阅我的帖子...EXC_BAD_ACCESS automatic handling

    【讨论】:

      猜你喜欢
      • 2016-12-28
      • 2018-05-29
      • 2018-08-22
      • 2019-10-04
      • 1970-01-01
      • 2018-12-18
      • 1970-01-01
      • 2018-09-21
      • 2023-03-16
      相关资源
      最近更新 更多