Question

Each time I write a method using an NSFetchRequest I faithfully include some version of the following boilerplate code:

NSError * error = nil;
NSArray * result = [context executeFetchRequest: fetchRequest error: &error];
if (!result && error) {
    NSLog(@"Error fetching - %@", error.localizedDescription);
}

However, I can't remember having ever seen executeFetchRequest fail and have error populated.

Certainly executeFetchRequestcan fail (trying to create invalid SQL, say) but this raises an exception, rather than returning an error.

So, my question is this: is it worth checking error each time, or would I be better to save myself the time and just write:

NSArray * result = [context executeFetchRequest: fetchRequest error: NULL];
Was it helpful?

Solution

It is always worth including it.

showing the error to an enduser is useless
BUT logging it is ALWAYS good as it may potentially help you to better locate & fix a bug

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top