I'm coding up various routines and I'm trying my best to keep it neat and refactored.
Methods I'm creating are starting to look similar to this code:
-(IBAction)buttonPress:(id)sender {
// Create Document Shopping List with this document
[self doSomething:&error];
if(error) {
[NSApp presentError:&error];
return nil;
}
[self doSomethingElse:&error];
if(error) {
[NSApp presentError:&error];
return nil;
}
[self doYetSomethingElse:&error];
if(error) {
[NSApp presentError:&error];
return nil;
}
}
I love NSError, but this seems like an awfully clumsy way of handling all my errors.
A few thoughts I've had about alternative ways:
a) the error checking could be built into the methods doSomething, doSomethingElse etc, but then I wouldn't be able to exit the button press method without doing some kind of checking on the return value, which would lead me back to a similar structure.
b) I could set up the NSError as being Key Value Observed, but something about this feels deeply wrong. I'm very aware of the possibilities of abuse with KVO, so I'm trying to do everything without it whereever possible.
Surely I'm missing something really basic here? Is there a pattern that can help me? Or is this structure OK?