Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.