我想捕捉许多陈述可以抛出的错误, ,而不必在每个陈述的开头写“尝试” 。
我写的:
do {
try couldThrowException1()
try couldThrowException2()
try couldThrowException3()
} catch {
handleExceptions()
}
我是怎么写的:
do {
couldThrowException1()
couldThrowException2()
couldThrowException3()
} catch {
handleExceptions()
}
答案 0 :(得分:0)
不幸的是,目前无法在Swift中实现。
您也可以使用
试试!
或
像这样:尝试?
let x = try? someThrowingFunction()
let x = try! someThrowingFunction()
但不安全