Created
June 29, 2015 04:26
-
-
Save fjolnir/4a88c93b985559afbf31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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