A clear majority of error handling in Rust is done via these two generic types, or a type that looks and behaves very much like them. Operations that might fail do not throw exceptions but rather return one of these types. You may be curious as to why Rust chose this method instead of the more mainstream approach of exceptions and stack unwinding. Let's think about that for a moment.
First of all, exceptions have an overhead. In a nutshell, they can be implemented in languages in two ways:
- Make the code that runs without errors very cheap, but error cases very expensive
- Make error cases very cheap, but non-error cases expensive
Neither of these works well with Rust's central philosophy of zero runtime cost.
Secondly, exception-style ...