----
*成功を結果の値、失敗を詳細で表す
<pre>
enum ErrReson : Error {
case overflow
case even
}
func someProc(_ underTenOddNum: Int) -> Result<String, ErrReson> {
if underTenOddNum >= 10 {
return .failure(.overflow)
}
if underTenOddNum % 2 == 0 {
return .failure(.even)
}
return .success("Success!! odd number & uner ten")
}
func checkResult(_ result: Result<String, ErrReson>) {
switch result {
case let .success(message):
print(message)
case let .failure(err):
print("\(err)")
}
}
checkResult(someProc(11))
checkResult(someProc(8))
checkResult(someProc(9))
</pre>
*結果
<pre>
overflow
even
Success!! odd number & uner ten
</pre<
====エラーを投げる====