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 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
- Where is the section on enumerated types?ComputerScienceOne · Checked Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . .
- How do you declare and use an enumerated type in Java?ComputerScienceOne · More Tricks