开发者

Replacing aborts() for unresolved errors in iPhone/CoreData

I have quite a few places in my iPhone application with a line like this:

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 e开发者_运维技巧rror, display an alert panel that instructs the user to quit 
  the application by pressing the Home button.
  */

  NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
  abort();
}

I'm sort of at a loss on what to actually replace abort() with in a production application. I don't suppose there's any simple way to allow users' devices to send the errors back to you. What's the standard practice here?


What I've done depends on what is happening in the application. If the save can be rolled back without affecting the application, you can just do that. That would be pretty rare. More likely, you are going to want to let the user know that their save failed. Depending on the cause of the failure, you can offer to try again or explain why it was invalid.

It basically depends on your application and how you would best serve the user.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜