do-try-catch多行代码

时间:2016-02-24 11:29:08

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

我想捕捉许多陈述可以抛出的错误, ,而不必在每个陈述的开头写“尝试”

我写的:

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

我是怎么写的:

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

1 个答案:

答案 0 :(得分:0)

不幸的是,目前无法在Swift中实现。

您也可以使用

  

试试!

  

尝试?

像这样:

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

但不安全