NSSetUncaughtExceptionHandler没有捕获iPhone上的所有错误 [英] NSSetUncaughtExceptionHandler not catch all errors on iPhone

查看:181
本文介绍了NSSetUncaughtExceptionHandler没有捕获iPhone上的所有错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 http://code.google.com/中使用GTMStackTrace p / google-toolbox-for-mac

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

I need a way to test end-user to send me errors when the app crash. I know how send data to my website but the problem is how catch all non-handled errors.

我有这个代码:

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;
}

然而,事情没有发生很多错误,像一个坏的版本, BAD ACCES等,App消失。我有两个问题,不清楚为什么发生,最终用户不知道该说什么。

However, the thing not caught a lot of errors, like a bad release, a BAD ACCES, etc, and the App disappear. I have 2 issues where is not clear why happend and the end-users have not clue about what to say.

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

(For example release twice the same var is not catch)

那么,我如何得到所有那些令人讨厌的错误,所以终端用户简单发送一个崩溃报告?

So, how I get ALL that pesky errors so the end-user simple send me a crash report?

推荐答案

EXC_BAD_ACCESS 不会产生异常,它会生成一个信号(SIGSEGV)。要抓住它,你需要一个信号处理程序。 Christopher Atlan写了一个很好的说明如何处理这两种事故。请务必阅读第1部分和第2部分。

EXC_BAD_ACCESS doesn't generate an exception, it generates a signal (SIGSEGV). To catch it, you need a signal handler. Christopher Atlan wrote a nice explanation of how to handle both kinds of crashes. Be sure to read both part 1 and 2.

这篇关于NSSetUncaughtExceptionHandler没有捕获iPhone上的所有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆