Guaranteed code execution in Swift
func throwIfTrue(param: Bool) throws {
do {
if param {
throw Exception.text
}
}
catch {
print("catch")
}
defer {
print("defer")
}
}
try! throwIfTrue(true)
//printed: "catch" and "defer"
try! throwIfTrue(false)
//printed only "defer"
- Log in to post comments