≈ the.bay.news

[Pitch] `guard do ... catch`: local error handling with early-exit and bound variables

Swift Forums
[Pitch] `guard do ... catch`: local error handling with early-exit and bound variables
Motivation It is a common pattern to have a throwing function whose result needs to be bound for use in the enclosing scope. let value = try thrower() // We want to handle any thrown errors and exit early // so that the value binding can stay un-nested. use(value) There are a few ways to achieve this today, none of which are ideal. do/catch The do/catch versions have multiple issues: do { let value = try thrower() use(value) // The happy path is nested } catch { // Error handling...

0 comments

Sign in to join the discussion — your thebay.events account works here.

No comments yet.