3 ms·
But errors that are returned by functions are expected behavior. Except for where you assert its bizarre you seem to support this position. The only semantic th
by segfaltnh 3y ago
But errors that are returned by functions are expected behavior. Except for where you assert its bizarre you seem to support this position. The only semantic thing rust offers here is '?', and that's just syntax sugar for errors are values.
Truly exceptional situations are those we don't expect, and for that we panic. I expect errors, because it's a computer and that's what they do.
- simiones 3y agoNo, the error path is a distinct concept from the success path, in almost all situations. The success path implements some kind of business logic, and will be highly specific to the task at hand. The error path almost always does nothing more than returning early with an indication that the operation failed (with some context about the failure) to an entity above, ultimately to the user. A minority of cases may involve an automatic retry of the operation. Anything else is vanishingly rare. As such, virtually all languages separate the business logic from the error logic. They offer exceptions, or Rust's ? macro, or enshrine certain error handling patterns (negative return codes in C, if err != nil in Go, use of the Either monad in Haskell).