【发布时间】:2015-12-08 21:27:30
【问题描述】:
我一直想这样做:
do {
let result = try getAThing()
} catch {
//error
}
do {
let anotherResult = try getAnotherThing(result) //Error - result out of scope
} catch {
//error
}
但似乎只能这样做:
do {
let result = try getAThing()
do {
let anotherResult = try getAnotherThing(result)
} catch {
//error
}
} catch {
//error
}
有没有办法在范围内保持不可变的result 而不必嵌套 do/catch 块?有没有办法防止错误,类似于我们使用 guard 语句作为 if/else 块的反转?
【问题讨论】: