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:
Note: When I posted this I was unaware of any MacOS/Cocoa exceptions debate. Please bear this in mind when you consider this answer.
Why not use exceptions instead? This will allow you to dispense with the error parameter on your methods and handle your errors in one place.
-(IBAction)buttonPress:(id)sender {
// Create Document Shopping List with this document
@try {
[self doSomething];
[self doSomethingElse];
[self doYetSomethingElse];
} @catch (NSException* e) {
[NSApp presentException:e];
}
return nil;
}
You will of course need to throw exceptions as required from within your doXXXX methods:
NSException* e = [NSException exceptionWithName:@"MyException"
reason:@"Something bad happened"
userInfo:nil];
@throw e;