Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 310911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:52:36+00:00 2026-05-12T07:52:36+00:00

I am developinga Core Data app for the iPhone, and I am new to

  • 0

I am developinga Core Data app for the iPhone, and I am new to the whole platform etc.

My question is, how much should I look for and handle errors and exceptions, for example when opening up the persistent store. Looking at the “Locations” Core Data Tutorial for example (hope its OK to quote it here like this):

(Se comments in the code for some of my conserns)

- (void)applicationDidFinishLaunching:(UIApplication *)application {
   ...    
   NSManagedObjectContext *context = [self managedObjectContext];
   if (!context) {
       // Handle the error. Can this ever happen with this code? (see next comment below)



- (NSManagedObjectContext *) managedObjectContext {
   ...
   NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
   // it seems even if I get an error or exception down in persistentStoreCoordinator,
   // coordinator will still never be nil, or?  
   if (coordinator != nil) {
        managedObjectContext = [[NSManagedObjectContext alloc] init];
        [managedObjectContext setPersistentStoreCoordinator: coordinator];
   }
   return managedObjectContext;   
}



- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
   ...
   NSError *error;
   // should i have an:  if managedObjectModel != nil   here?
   persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] [initWithManagedObjectModel: [self managedObjectModel]];
   //need a @try here too?
   if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error]) {
       // Handle error, do what?   
   }    
   return persistentStoreCoordinator;    
}


- (NSManagedObjectModel *)managedObjectModel {
   ...
   //should have a @try here? But how to handle caught exceptions? Just return nil?
   managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];    
   return managedObjectModel;
}

So the question is really where to look for errors, where to look for exceptions, how and when to propagate them upwards, and how to handle severe errors on the iPhone in a good way?


Edit: after receiving some answers to this and my other related question I have some clearifications of what I try to ask:

I now understand exceptions in cocoa are mostly for finding programmer errors, not runtime errors. Would you go as far as not including any exception handling when shipping the app (if not added for debug reasons)? Or should I still program defensively and use a lot of @try anyway?

As the iPhone apps are sandboxed and the user cant get to the file system, what possible runtime errors are smart to look for when designing a sqlite based core data app? I mean, the database file is not likely to disapear….but perhaps a future upgrade could fail leaving an old invalid sqlite database….what is good practise?

Also, other things like object alloc are probaly extremely unlikely to fail? You would get a low memory warning long before that happens….or…?

And, what is good programming practise considering error and exception handling in the above example, where I can get an error “deep down” in the methods…should I handle the error down there or wait until it reaches the top in some form (a nil object for example), or handle them all in a chain reaction?

And, how to handle them? Log to NSLog and go on? Show a modal info box and lock up waiting for the user to exit the app? Or “Error xxx, press OK to exit app”?

And, is there any way to show a modal dialog directly? I noticed that some errors I provoked that would display a dialog never showed that because the app continued and later crashed….is there a SHOW NOW method?

Lots of questions, hope you would be interested to answer at least some of them, and that this could be of interest to others!

Rgds
PM

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:52:36+00:00Added an answer on May 12, 2026 at 7:52 am

    As I said in a comment on your other question, exceptions are only used by the Cocoa API to indicate things that it looks like the programmer has got wrong – an array is out of bounds, a Core Data database has the wrong schema etc. Errors are used to indicate things which the user could cause to happen – a file doesn’t exist, a network operation didn’t complete etc. So as a rough rule of thumb, look for exceptions during development and crush them as programmer-introduced bugs. Be prepared to handle and recover from errors in production.

    The one important edge case on the Mac is Distributed Objects, which uses exceptions for things like the other end of the connection going away or the security validation not succeeding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 220k
  • Answers 220k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can maybe use WMI to get the results. Herewith… May 12, 2026 at 11:57 pm
  • Editorial Team
    Editorial Team added an answer Well, the error message really says it all: Every binding… May 12, 2026 at 11:57 pm
  • Editorial Team
    Editorial Team added an answer A BigInt in SQL Server is equivalent to the int64… May 12, 2026 at 11:57 pm

Related Questions

I am developing an iPhone app using Core Data and ahev noticed that I
I'm developing for iphone-sdk 2.2.1 (so no CoreData cry ). So I'm using the
I need to store large amounts of metering data in a database. A record
I am Developing A Core Data App, and would like to add a feature

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.