NSSetUncaughtExceptionHandler 无法捕获 iPhone 上的所有错误 [英] NSSetUncaughtExceptionHandler not catch all errors on iPhone
问题描述
我正在使用来自 http://code.google.com/的 GTMStackTracep/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;
}
然而,事情并没有发现很多错误,比如发布错误、访问错误等,然后应用程序消失了.我有两个问题不清楚为什么会发生,最终用户不知道该说什么.
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 part 2.
这篇关于NSSetUncaughtExceptionHandler 无法捕获 iPhone 上的所有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!