Question

Looking at the Error Handling Programming Guide, I understand that in cases like the following I must never evaluate the NSError parameter theError unless the return value is NO

BOOL success = [myDoc writeToURL:[self docURL] ofType:@"html" error:&theError];

What happens in casses when the return value is not a success BOOL, and instead it is a collection object?

Take for example [NSIncrementalStore obtainPermanentIDsForObjects:error]. I must not evaluate an error using the error parameter. What should I look for? I imagine I could receive either a nil pointer or an empty array. In this case an empty array does not seem a good response, although in other functions an empty array might be a good one. I can read that if an error occurs, the error object will contain a description of what happened, but it is not so clear how can I find out that an error actually happened.

What is the normal Cocoa or Foundation way to indicate an error in cases like these?

Was it helpful?

Solution

For that method, you're expected to return an array of as many items as you had objects passed in. I'd say that if you don't do that (either the array is nil or empty), you're in an error condition, since you're violating what the documentation says will happen:

An array containing the object IDs for the objects in array.

The returned array must return the object IDs in the same order as the objects appear in array

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