Conversation

Given the unwieldlyness of exceptions, perhaps what I would really want in an OOP language is a construct to say "return from this function, AND the calling function, and return value X from the calling function.".
6
12
Replying to
This gets tricky when you consider different return types. This either requires that functions don't declare a return type, or that all of them return some kind of "result" type.
1
Replying to and
You define a sum type with the possible errors and implement the From trait for implicitly converting from each. For example, #[derive(From)] enum MultipleError { One(ErrorOne), Two(ErrorTwo) }. You can use the ? operator (or the legacy try!) to return one of the variant types.
1
Using this sugar for propagating the error upwards is only one small part of using it. It's very misleading to portray it as the same thing as checked exceptions just because one small aspect of it is superficially similar (and yet much different since control flow is explicit).
1
Show replies