> On Jul 8, 2017, at 3:08 PM, Christopher Kornher via swift-evolution
> <[email protected]> wrote:
>
> I am opposed to this proposal because it muddies up the language to support
> what is essentially an edge case. The standard way to exit a function early
> because an exception is thrown is to make the function itself throw, if it is
> part of a larger operation. The addition of a few lines of try/catch code is
> not a great burden and makes the termination of an an exception very clear.
Not such an edge case, if you write asynchronous code:
func doSomething(completionHandler: @escaping (Error?) -> ()) {
guard let foo = try makeFoo() catch {
completionHandler(error)
return
}
doSomeAsyncThing(with: foo) {
do {
try parseTheResult($0)
completionHandler(nil)
} catch {
completionHandler(error)
}
}
}
With the existing facilities, one must either use this rather awkward
construction to make foo:
func doSomething(completionHandler: @escaping (Error?) -> ()) {
let foo: Foo
do {
foo = try makeFoo()
} catch {
completionHandler(error)
return
}
doSomeAsyncThing(with: foo) {
do {
try parseTheResult($0)
completionHandler(nil)
} catch {
completionHandler(error)
}
}
}
Or, alternatively, construct a pyramid of doom:
func doSomething(completionHandler: @escaping (Error?) -> ()) {
do {
let foo = try makeFoo()
doSomeAsyncThing(with: foo) {
do {
try parseTheResult($0)
completionHandler(nil)
} catch {
completionHandler(error)
}
}
} catch {
completionHandler(error)
}
}
Charles
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution