2 ms·
> Obviously it'd be nice if that didn't happen, but I can't think of any alternative that would make sense. Returning a sum of success + error, as e.g. Rust's
by masklinn 8y ago
> Obviously it'd be nice if that didn't happen, but I can't think of any alternative that would make sense.
Returning a sum of success + error, as e.g. Rust's Serde[0] or Elm's Json.Decode[1] do.
The developer gets the feedback that the operation has failed at runtime, but they also get the feedback that the operation can fail and they must handle it somehow at compile-time, even ignoring the issue is an explicit decision.
[0] https://docs.serde.rs/serde_json/de/fn.from_str.html https://docs.serde.rs/serde_json/de/fn.from_str.html
[1] http://package.elm-lang.org/packages/elm-lang/core/latest/Json-Decode#decodeString http://package.elm-lang.org/packages/elm-lang/core/latest/Js...
- bad_user 8y agoIn Scala too well grown libraries return errors via sum types, e.g. Either. In Play this is actually something like JsSuccess/JsError, not an exception, although Play is pragmatic (aka dirty) at times, so it's possible that it has functions throwing exceptions.