Catch an exception for invalid user input in swift

More “Swifty” solution: @implementation TryCatch + (BOOL)tryBlock:(void(^)())tryBlock error:(NSError **)error { @try { tryBlock ? tryBlock() : nil; } @catch (NSException *exception) { if (error) { *error = [NSError errorWithDomain:@”com.something” code:42 userInfo:@{NSLocalizedDescriptionKey: exception.name}]; } return NO; } return YES; } @end This will generate Swift code: class func tryBlock((() -> Void)!) throws And you can use … Read more