Is it possible to make early exit in do-try-catch block? (Like `guard`)

If I understand you correctly you want to sugar over this:

let value: Value
do {
  value = try getValue()
} catch {
  print(error)
  return // in your case this would be required
}

// use value here

Is that correct?


I pitched something like this myself before and IIRC this is also known by the community as guard catch.

3 Likes