C++ Enum Class and Error Codes
mropert.github.io·1w·
Discuss: Hacker News
🔒Type Safety
Preview
Report Post

03 Dec 2025 on C++

Last time we explored some commonly found alternatives to using enums for error codes such as asserts, contracts and std::expected. Finally today we consider some unthinkable options.

The code examples given in part 1 and part 2 strongly focused on simple (and I’d argue, quite common) form of error handling: run a sequence of operations, and if any of them fails bail out and report an error. We tried a few alternatives but they all came with caveats. Error code returns polluted a lot of the logic with if ( error ) { return error; }, std::expected was a bit more concise but demanded we rew…

Similar Posts

Loading similar posts...