Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone Core Data "Production" Error Handling

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.

Thanks in advance, Matt

like image 445
Sway Avatar asked Feb 14 '10 20:02

Sway


1 Answers

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

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.

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.

like image 156
Marcus S. Zarra Avatar answered Sep 20 '22 11:09

Marcus S. Zarra