Concept
Why are enumerated types better than arbitrary integer error codes?
ComputerScienceOne / Enumerated Types
"The usage of the integers 1, 2, 3 to indicate the various errors was arbitrary. These are essentially magic numbers that the calling function would have to deal with by making comparisons with various integers. The numbers themselves are meaningless and someone using them would need to constantly refer to documentation to understand which integer corresponded to which error condition. It would be much better if we could follow the strategy of the errno and define human-readable identifiers for each error code. We could accomplish this by defining macros, but another solution is to use an enumerated type."
Related Ideas
- How can enumerated types be used for error codes in C?ComputerScienceOne · Using Enumerated Types for Error Codes
- How can a quadratic roots function return error codes?ComputerScienceOne · Error Handling By Design
- How do enumerated types represent named values in C?ComputerScienceOne · Using Enumerated Types for Error Codes
- What advantages do enumerated types provide in Java?ComputerScienceOne · More Tricks
- What are POSIX Error Codes?ComputerScienceOne · POSIX Error Codes
- What topics are covered in error handling?ComputerScienceOne · Function Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . .
- Why must software handle errors in addition to avoiding bugs?ComputerScienceOne · Error Handling
- How do you declare and use an enumerated type in Java?ComputerScienceOne · More Tricks