I am writing an API that wraps some core foundation web functionality that can return a number of possible error conditions. I am struggling with deciding the best way to handle error conditions that the API consumer should deal with (like network timeouts, receiving unexpected results, malformed XML, etc). I have come up with 3 different models, but am uncertain about which model to use:
Given an object with a method takeAction
that does not return any value, should I handle an error in the method by:
write the method to be
- (BOOL)takeAction:(NSError **)error
so that the consumer knows the method succeeded or failed, and can inspect the error object to determine why,write the method to be
- (BOOL)takeAction
so that, again, the consumer knows if the method succeeded or failed, and can then call- (NSError *)getLastError
to determine why the method failed, orwrite it as
- (void)takeAction
and post a notification so that the consumer can subscribe to the notification and pass the NSError object in the notification's userInfo dictionary?
Which is preferable?