Skip to content

Instantly share code, notes, and snippets.

@itod
Created June 19, 2015 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save itod/bbc9c2ee250084e3b639 to your computer and use it in GitHub Desktop.
Save itod/bbc9c2ee250084e3b639 to your computer and use it in GitHub Desktop.
Try/Finally with no exceptions in sight.
//
// main.m
// Finally
//
// Created by Todd Ditchendorf on 6/19/15.
// Copyright (c) 2015 Todd Ditchendorf. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
@try {
return 0;
}
@finally {
NSLog(@"OHAI");
}
}
return 0;
}
@itod
Copy link
Author

itod commented Jun 19, 2015

Or, to be a bit more clear about the kinds of things that could happen depending on runtime values:

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        @try {
            BOOL yn = YES;
            if (yn) {
                NSLog(@"Early return.");
                return 0;
            }
            NSLog(@"Never reached.");
        }
        @finally {
            NSLog(@"OHAI");
        }
    }
    return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment