Generally speaking, goto is bad (we all know why). What would be the best way to implement simple error cleaning (as in the example below) without duplicating code. In my opinion, the code below is fine, I was just wondering what others would do:
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]
int returnCode = 0;
if([dataStore writeToFile:savePathData atomically:YES] == NO) {
NSLog(@"writeToFile ... Error");
returnCode = 1;
goto cleanUpCode;
}
cleanUpCode:
[archiver release];
[newPlanet release];
[pool drain];
return(returnCode);
}
EDIT_001:
In general terms, I agree that @try, @catch, @finally is more than certainly the way to go, but I have two small problems.
(1) The three blocks @try, @catch, @finally should be together; you do not have the flexibility to put code between @catch and @finally, which you can bypass.
(2) The Apple documentation for Obj-C 2.0 reads as follows: "Important: Exceptions are resource intensive in Objective-C. You should not use exceptions for general flow control or simply to indicate errors (for example, a file is not available).
much appcreciated
Gary