Summary
Use plain old integers for error handling.
Motivation
- I’m not smart enough to understand the other error handling proposals.
- The simplest thing we can possibly do. This has been around since the dinosaurs, and for good reason.
errno
has problems in C of course, butResult
eliminates most of them. - It’s hard to imagine a newbie from another language who doesn’t already know how to use error codes. Prolog perhaps?
- Does not require nonexistent language features, runtime support or horrible performance (allocation).
Detailed design
- Introduce a new data structure to the standard library,
struct Errno(pub u32)
. - Use it everywhere.
- Tell people to use it everywhere else.
- Optionally, maintain a library of globally unique aliases and related stuff.
- Live happily ever after.
Drawbacks
The compiler cannot constrain the set of errors each function can emit. Careless use of try!
can lead to a situation much like C++ where only a recursive multi-library code audit will reveal all the exceptions thrown. RFC 70 does not solve this either.
No error chaining, if that’s a drawback.
Alternatives
RFC 70, exceptions, variadic templates, enum merging etc.
Unresolved questions
Whether there are any unresolved questions.