I like the Rust way of error handling. For those unfamiliar, there is a Result enum which can be Ok or Err. This is returned to indicate success or failure (so no `throw ` or bare booleans/integers).
In many cases, a failure needs to be propagated several stack frames. Because `if … return ` constructs get tedious, Rust has the `? ` postfix.
I like the idea, but I’d prefer a (prefix) keyword. Imagine it’s for a new language.
So if (no specific language):
function do_thing(): Result<T, E>
Then
THE_KEYWORD do_thing()
Translates to
if let Err(x) = do_thing() { return Err(x); }
So essentially the same as Rust’s
do_thing()?
My questions:
No responses yet.