【问题标题】:do-try-catch many lines of codedo-try-catch 多行代码
【发布时间】:2016-06-06 16:05:36
【问题描述】:

我想捕捉许多语句可能引发的错误,不必在每个语句的开头写“try”

我写的:

do {
    try couldThrowException1()
    try couldThrowException2()
    try couldThrowException3()
} catch {
    handleExceptions()
}

我想怎么写:

do {
    couldThrowException1()
    couldThrowException2()
    couldThrowException3()
} catch {        
    handleExceptions()
}

【问题讨论】:

    标签: ios iphone swift error-handling try-catch


    【解决方案1】:

    很遗憾,目前还不能在 Swift 中实现。

    你也可以使用

    试试吧!

    试试?

    像这样:

    let x = try? someThrowingFunction()
    let x = try! someThrowingFunction()
    

    但它并不安全

    【讨论】:

      猜你喜欢
      • 2016-09-30
      • 2015-08-23
      • 1970-01-01
      • 2018-08-03
      • 1970-01-01
      • 2018-03-04
      • 1970-01-01
      • 2016-02-14
      • 2019-07-30
      相关资源
      最近更新 更多