|
|
|
|
|
by kibwen
4408 days ago
|
|
> This seems like a step back from Exceptions to me. I
> want to be convinced otherwise, but I'm struggling to
> see how this is better than other mechanisms.
In a low-level language, guaranteeing memory safety in the face of resumable exceptions would be a nightmare. See Graydon's original post on the choice to avoid exceptions:https://mail.mozilla.org/pipermail/rust-dev/2013-April/00381... Selected quote: > In particular, to summarize for the impatient: once you get resumable
> exceptions, your code can only be correct if it leaves every data
> structure that might persist through an unwind-and-catch (that it
> acquired through &mut or @mut or the like, and live in an outer frame)
> in an internally-consistent state, at every possible exception-point.
> I.e. you have to write in transactional/atomic-writes style in order to
> be correct. This is both performance-punitive and very hard to get
> right. Most C++ code simply isn't correct in this sense. Convince
> yourself via a quick read through the GotWs strcat linked to:
> http://www.gotw.ca/gotw/059.htm
> http://www.gotw.ca/gotw/008.htm
For more on the topic of exception-safety in C++, see the following paper by Bjarne Stroustrup:http://www.stroustrup.com/except.pdf I don't think that Rust's error handling solution is ideal, but I think that it might be approaching the best possible solution for its chosen context. Error handling is a hard problem! |
|