小编Mym*_*odo的帖子

嵌套做抓住swift 3.0

我想使用连续的try语句.如果有人返回错误,我想继续下一个,否则返回值.下面的代码似乎工作正常,但我最终会得到一个大的嵌套do catch金字塔.在Swift 3.0中有更聪明/更好的方法吗?

do {
    return try firstThing()
} catch {
    do {
        return try secondThing()
    } catch {
        return try thirdThing()
    }
}
Run Code Online (Sandbox Code Playgroud)

error-handling swift do-catch

8
推荐指数
2
解决办法
1362
查看次数

标签 统计

do-catch ×1

error-handling ×1

swift ×1