enum Exception: Error {
case text
}
func throwIfTrue(_ param: Bool) throws {
defer {
print("defer")
}
do {
if param {
throw Exception.text
}
}
catch {
print("catch")
}
}
try! throwIfTrue(true)
//输出 "catch" 和 "defer"
try! throwIfTrue(false)
//只输出了 "defer"