Created
July 29, 2015 16:25
-
-
Save erica/e3f6820c968b4f50b7a6 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
func betterDoSomething() throws -> String { | |
let success = (arc4random_uniform(2) == 1) // flip a coin | |
if success {return "success"} // succeed | |
throw Error.Unlucky // fail | |
} | |
func client1() throws -> String { | |
let string = try betterDoSomething() | |
// blah blah other work | |
return string | |
} | |
func client2() throws -> String { | |
let string = try client1() | |
// blah blah other work | |
return string | |
} | |
func consumer() { | |
do { | |
let string = try client2() | |
print("String consumed: \(string)") | |
} catch { | |
print("Error handled here (\(error))") | |
} | |
} | |
consumer() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment