Petter Magnusson
Petter Magnusson

Reputation: 309

Core Data - Hoping for errors, getting exceptions

I am developing an iPhone app using Core Data and ahev noticed that I get exceptions when I would expect and error, this is an example:

NSError *error;

// exception here if edited attribute name todoText in modeller and generated new database with that new name in it(ie clearing the iphone), ie tring to access a field not in the database

@try {

   NSMutableArray *mutableFetchResults = [[todoListManagedObjectContext   executeFetchRequest:request error:&error] mutableCopy];

   //seems like vars declaered inside a try is only known inside it, so process here

   if (mutableFetchResults == nil) { // nil = error

      // Handle the error.

As seen in the comments I don't get an error for trying to access a non existing field....why not just use the error return system for this?

I guess my question is, what are errors and exceptions for, and do I really need to test for both like this?

Rgds PM

Upvotes: 1

Views: 245

Answers (1)

user23743
user23743

Reputation:

What exception are you getting? Throughout Cocoa, exceptions generally mean programmer error so it suggests you're passing a parameter which is not valid. Trying to access a field which isn't in the database seems like such a situation; it's not a "something went wrong" error, it's a "you did something wrong" error.

Upvotes: 3

Related Questions