[[!tag learning-rust]]
Error handling is one of the aspects of programming that tends to be most tedious and most error prone.
The
?
operator in Rust makes error handling be quite easy, but still requires declaring functions as returning aResult
. That's not too difficult. However, it's not enough to use use the handy operator for good error handling: at some point, something needs to actually handle the error result, or the program will crash. This is similar to exceptions in Python. But at least Rust makes it explicit what functions can return an error, and strongly guides you to handle those results.New thing:
std::error::Error
for defining one's own errors.Thought: how does Rust handle out-of-memory errors? None of the
new
functions return any kind of error, it seems to me, and new "objects" get created all the time. Just crash?I don't really understand
error-chain
.chain_err
seems like an interesting approach.Overall, looks like Rust may have some useful machinery for handling errors. More importantly, the type systems makes if more difficult to just ignore errors, which I like. I may have to use Rust for a while to appreciated the error handling, though.