iPhone核心数据“生产”错误处理 [英] iPhone Core Data "Production" Error Handling

查看:182
本文介绍了iPhone核心数据“生产”错误处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Apple提供的示例代码中看到了如何处理Core Data错误。 I.e:

I've seen in the example code supplied by Apple references to how you should handle Core Data errors. I.e:

NSError *error = nil;
if (![context save:&error]) {
/*
 Replace this implementation with code to handle the error appropriately.

 abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
 */
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    abort();
}

但永远不会有任何例子

But never any examples of how you should implement it.

有没有一个实际的生产代码来描述上述方法。

Does anyone have (or can point me in the direction of) some actual "production" code that illustrates the above method.

提前感谢,
Matt

Thanks in advance, Matt

推荐答案

没有人会向您显示生产代码因为它取决于你的应用程序和错误发生的地方。

No one is going to show you production code because it depends 100% on your application and where the error occurs.

就我个人而言,我在其中放置一个assert语句,因为99.9%的时间这个错误会发生在开发中,当你修复它,它是高度不太可能你会看到它在生产中。

Personally, I put an assert statement in there because 99.9% of the time this error is going to occur in development and when you fix it there it is highly unlikely you will see it in production.

在断言后,我会向用户发出警告,让他们知道发生了不可恢复的错误,并且应用程序将要退出。

After the assert I would present an alert to the user, let them know an unrecoverable error occurred and that the application is going to exit. You can also put a blurb in there asking them to contact the developer so that you can hopefully track this done.

之后,我会将abort()放在那里它会崩溃的应用程序,并生成一个堆栈跟踪,你可以希望以后使用以跟踪问题。

After that I would leave the abort() in there as it will "crash" the app and generate a stack trace that you can hopefully use later to track down the issue.

这篇关于iPhone核心数据“生产”错误处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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