为什么这个代码在分布式应用程序中崩溃,但在调试器中工作? [英] Why does this code crash on the distributed app but work in the debugger?

查看:130
本文介绍了为什么这个代码在分布式应用程序中崩溃,但在调试器中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 我有简单的代码执行,如果它崩溃,我想抓住异常,所以应用程序不会崩溃。 > @try {
x = [self try_doMyWork:Param];
} @catch(NSException * e){
NSLog(@Exception);
}

虽然此代码在调试中工作,并捕获异常(这是一个简单的索引



为什么会这样,我如何确保它也适用于分布式应用程序?

解决方案

未捕获的应用程序级异常只是崩溃的一个原因。 BSD信号,如EXC_BAD_ACCESS,也可能导致崩溃,并且捕获NSExceptions将不会阻止这些。



不知道try_doMyWork的详细信息是不可能的, :但是,我认为C层(而不是Objective-C层)中最常见的崩溃原因是内存管理问题 - 尝试编写或读取应用程序不应该访问的内容。最有可能的解释是,在调试中看到的异常与分发中看到的错误不同。


I have simple code that executes and in case it crashes I want to catch the exception so the app does not crash.

@try {
    x = [self try_doMyWork:Param];
} @catch (NSException* e) {
    NSLog(@"Exception");
}

While this code works in debug and catches the exception (which is a simple index beyond end of array) it crashes in distributed apps on iPhones.

Why is this and how can I ensure that it also works on distributed apps?

解决方案

Uncaught application-level exceptions are only one cause of crashes. BSD signals, like EXC_BAD_ACCESS, can also cause crashes - and catching NSExceptions won't prevent those.

It's impossible to say what the specific crash is without knowing the details of try_doMyWork:, but I think the most common cause of crashes in the C layer (not the Objective-C layer) is memory management problems - an attempt at writing or reading something your app is not supposed to access. The most likely explanation is that the exception you see in debug is not the same as the error you see in distribution.

这篇关于为什么这个代码在分布式应用程序中崩溃,但在调试器中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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