NSSetUncaughtExceptionHandler没有捕获所有的错误在iPhone上 [英] NSSetUncaughtExceptionHandler not catch all errors on 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)。要捕捉它,你需要一个信号处理程序。克里斯托弗·阿特兰写了一篇很好的解释如何处理两种类型的崩溃。请务必阅读第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屋!