Skip to content

Instantly share code, notes, and snippets.

@fjolnir
Created June 29, 2015 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fjolnir/4a88c93b985559afbf31 to your computer and use it in GitHub Desktop.
Save fjolnir/4a88c93b985559afbf31 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
#define Attempt(...) ({ \
NSError *__err; \
typeof([__VA_ARGS__ error:NULL]) __result = [__VA_ARGS__ error:&__err]; \
if(!__result) \
@throw __err; \
__result; \
})
int main(int argc, char *argv[]) {
@autoreleasepool {
@try {
NSString *str = Attempt(NSString stringWithContentsOfFile:@"foo" encoding:NSUTF8StringEncoding);
} @catch(NSError *err) {
NSLog(@"%@", err);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment