【发布时间】:2016-01-06 13:06:39
【问题描述】:
我有一个函数 assignName(name:) 会引发错误。当从具有多个 catch 的 do 块调用该函数时,它显示错误为:
Errors thrown from here are not handled because the enclosing catch is not exhaustive
我的代码是:
enum PersonError: ErrorType {
case IsNotAPerson
case IsNotAGoodPerson
case IsNotAValidPerson
}
func assignName(name: String?) throws {
guard name != nil else {
throw PersonError.IsNotAPerson
}
personName = name
}
func catchingSpecificError() {
do {
try assignName(nil) // Compiler Error displays at this line.
}catch PersonError.IsNotAPerson {
print("Propagated error is caught in catch on case .NotAPerson")
}
}
提前致谢!
【问题讨论】:
-
我刚刚意识到这是完全重复的:stackoverflow.com/questions/30720497/…