Skip to content

Instantly share code, notes, and snippets.

@ukitaka
Created December 12, 2016 06:30
Show Gist options
  • Select an option

  • Save ukitaka/7fadcbe1e93b4cfab169d4dbfc8215ec to your computer and use it in GitHub Desktop.

Select an option

Save ukitaka/7fadcbe1e93b4cfab169d4dbfc8215ec to your computer and use it in GitHub Desktop.
置換モデルでthrowsが純粋じゃないことを示す例
enum Error: Swift.Error {
case castError
}
func toInt(_ string: String) throws -> Int {
guard let i = Int(string) else {
throw Error.castError
}
return i
}
func myFunc() throws {
let hoge = try toInt("123")
do {
let fuga = try toInt("123") + hoge
print(fuga)
}
catch {
print("^_^;")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment