Skip to content

Instantly share code, notes, and snippets.

@erica
Created July 29, 2015 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save erica/e3f6820c968b4f50b7a6 to your computer and use it in GitHub Desktop.
Save erica/e3f6820c968b4f50b7a6 to your computer and use it in GitHub Desktop.
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