views:

166

answers:

1

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 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();
}

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?

+3  A: 

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.

Don
I agree with Don. At least you should present an Alert to the user with details of what went wrong. Perhaps an option to send a report to you so that you can fix the issue in the next release.Having said that, these errors *should* never occur in the wild. Errors with Core Data, in my experience, almost always occur in development if adequate testing has been conducted. The only issue I have seen in the wild with Core Data directly involves migration and that is usually on the desktop.
Marcus S. Zarra
Yeah, I was worried this was one of those "no real answer" kind of questions. :) By my reckoning, no errors should be thrown, which means that if any are, I'm wrong about something... which would be disconcerting.Thanks, everyone!
AndrewO