Chapter 15: Error Handling with Result
Reliable software requires robust error handling. In C, error management often relies on conventions like special return values (e.g., -1
, NULL
) or global variables (e.g., errno
). These methods require discipline, as the compiler does not enforce error checks, making it easy to overlook potential failures. C++ introduced exceptions, offering a different model but with its own complexities.
Rust tackles error handling differently, integrating it into the type system. It distinguishes between errors that are expected and potentially recoverable, and those that signify critical, unrecoverable problems (often bugs). This distinction is enforced by the compiler, guiding developers to acknowledge and handle potential failures appropriately.