Rust Error Handling
The cluster focuses on discussions about Rust's Result type, ? operator, and error propagation mechanisms, often praising it as superior to exceptions in C++/Java or verbose checks in Go/C, with mentions of crates like anyhow and thiserror.
Activity Over Time
Top Contributors
Keywords
Sample Comments
You might like how Rust does error handling. Rather than a function returning a triple of (val, error) where the error can be ignored, functions return Result. If you want to get the T, you must write code that handles both possibilities. If your function instead wants the T and propagate the E upwards if it exists, you can do that with one character - “?”
Rust's error handling (try! and error-interoperability) do this well.
I guess many people don't have problem with the 'errors are values' concept, just would like to handle them with much less boilerplate: like in Rust or Haskell...
There is no better way to do errors imo, unless you're going the erlang way of "let it fail". Errors can be passed to the caller the same way exceptions are, and it becomes an endless pursuit of where the error is actually being handled (if at all). I agree that some syntax sugar helps, see Rust, but it doesn't completely fixes the problem.
Is it time to brag about Rust error-handling or should we wait a little?
Rust has error handling personality.
Don't care for the way they do exceptional handling. Make errors part of the type system
Yes.Rust struggled with that for about three rounds of verbose error handling, until finally settling on "Result" and "?". That seems to be about right. C++ exceptions are too much. Writing it all out as in C and Go is too little. The Rust solution is a good midpoint.
Yes! Rust's error handling story is excellent.You can still swallow errors if you want to but you have to manually write unwrap() so it's much more visible.
Agreed, Rust's way of error handling with Result and try! (or ?) is far superior.