2 ms·
With Rust & Go style error handling you generally still do bubble up errors and handle them centrally. But you don't always want to do that. Sometimes you want
by IshKebab 3y ago
With Rust & Go style error handling you generally still do bubble up errors and handle them centrally. But you don't always want to do that. Sometimes you want to handle errors locally and e.g. retry things, or try something else in case of an error or ignore some errors etc. You also should add context (`raise ConfigParseError() from int_parse_error`) which approximately 0% of people do with exceptions.
Handling errors locally is difficult to do with exception handling because it's impossible to tell what errors a function might produce (if any!). It's also more verbose (especially compared to Rust) which just makes it annoying.
Checked exceptions are the usual answer to this but they're so tedious most people don't bother with them. C++ even dropped support for them from the language.
Rust's error handling is much better than exceptions in almost every way.
- riffraff 3y agoWhy do you think nobody wraps exceptions? Everyone did in every project in every language I've worked on. Every rest API client library will wrap the http library errors which will wrap network errors. Languages even directly support the notion of keeping a reference to the original exception. If anything, people do it too much.
- berkes 3y agoThere's always that edge case, say "FileReadTimedOut" presented as a UncaughtServerError that no developer ever knew the existence of, let alone thought to wrap it (in, say, the LogoStorage). With Rust this situation is impossible. Unexpected errors are made impossible by the type checker, a dev must handle it. Sure, a dev may say "meh, I'll just .into() (or wrap, if you want) any error that file-io gives into NotFound" but she does so knowingly and actively.