4 ms·
No, `try` can be applied to any expression, and will "try" all throwing calls in subexpressions of that: func f() throws -> Int { return 0 } func nothing(_
by dbaupp 8y ago
No, `try` can be applied to any expression, and will "try" all throwing calls in subexpressions of that:
func f() throws -> Int { return 0 }
func nothing(_ x: Int) {}
func g() throws {
nothing(try f())
try (f() + f())
try nothing(f() * f())
}
This includes method chains:
struct Foo {
init() throws {}
func bar() throws -> Foo { return self }
func qux() throws -> Foo { return self }
}
try Foo().bar().qux()
- kibwen 8y agoCool, thanks, I looked in the official docs but didn't notice any mention of this feature. :)