Created
December 12, 2016 06:30
-
-
Save ukitaka/7fadcbe1e93b4cfab169d4dbfc8215ec to your computer and use it in GitHub Desktop.
置換モデルでthrowsが純粋じゃないことを示す例
This file contains hidden or 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
| 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