Looking at you, syscall!
Looking at you, syscall!
Technically, you can implement that spec for all OSes. I did a few times, defining vendor-specific facilities for Linux components I used, like xwindows, drm/kms, etc..
For that use case you gonna need some other piece of data besides the error code. Maybe another type like json_error_t in Jansson library. Or maybe a special strings, like the ones returned by sqlite3_errmsg() in SQLite library.
> not something you should replicate in your own code if you have the choice
I believe HRESULT, despite rather old, is still the best error handling strategy overall.
Language-specific solutions like std::expected don’t work because all complicated software is written in multiple programing languages. For example, the entire ML ecosystem uses Python. 32-bit integers and strings are as language agnostic as you can possibly get.
Enums don’t work because most non-trivial libraries have an unbounded number of possible error conditions. You made a parser library for some format, defined an enum containing all possible failures of the parser, but then a user tried to parse a file he doesn’t have read access to. The failures need to include disk I/O errors. Another user gonna parse their source file from a mounted network share, the failures returned from your parser now need to include TCP/IP errors.
They aren't alone, Apple's XPC, Android and Fuchsia's Binder, and even Linux D-DBus, aren't much different.
They have much better tooling though, something that Microsoft folks keep ignoring, so I understand where the pain comes from.
of course, there are reasons for mucking around with pointers. but down that route lies pointers-to-pointers, and eventually madness.