Created
July 25, 2015 06:13
-
-
Save haranicle/6b8679a6e06ba513fa74 to your computer and use it in GitHub Desktop.
do-catchについて #cswift #CodePiece
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
// エラーハンドリング専用構文 | |
do { | |
// エラーが発生する可能性があるコード | |
} catch { | |
// エラー発生時の処理 | |
} | |
// 例 | |
do { | |
var handle = try File.open(path) | |
} catch { | |
// errorはErrorType型の変数 | |
print(error) | |
} | |
do { | |
} catch FileOperationError.NotPermitted(let reason) { | |
} catch let error = PiyoError { | |
} catch is HogeError{ | |
} catch { | |
} | |
var handle = try! File.open(path) | |
// とかくとdo-catchいらず。エラると強制終了。 | |
// 呼び出し元にエラーの一部を委ねることもできる | |
func execute() throws -> String { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment