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

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

问题描述

我在 Apple 提供的示例代码中看到,您应该如何处理 Core Data 错误.即:

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.

提前致谢,马特

推荐答案

没有人会向您展示生产代码,因为它 100% 取决于您的应用程序以及发生错误的位置.

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天全站免登陆