Skip to content

Instantly share code, notes, and snippets.

@hvsw
Last active February 15, 2016 05:53
Show Gist options
  • Save hvsw/b6e1b9f11e671acff735 to your computer and use it in GitHub Desktop.
Save hvsw/b6e1b9f11e671acff735 to your computer and use it in GitHub Desktop.
// Using optional try
let x = try? divide(0, 2) // (Yes you can use an if let/guard/whatever to unwrap it safely)
// Using do-catch
let y: Float?
do {
y = try divide(0, 2)
} catch { // exhaustive just for testing
y = nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment