Could there be cultural differences according to your coding language?
In Java, for example, numeric error codes are not used much ...
Regarding exceptions, I think this is just a technical tool. The important thing is that your message is intended for the user or developer. It is important for the user to localize messages if several languages ββappear or the ability to change messages without recompiling (to configure between clients, to adapt to changing user needs ..).
In my projects, our culture is to use (java) enumerations to process all sets of fixed values. Errors are no different. Enumerations for errors can provide:
- strong typing (you cannot pass anything else to a method expecting an error code)
- simple localization (a simple utility method can automatically find a message corresponding to each of them, using, for example, "SimpleClassName". The template "INSTANCE_NAME", you can also expose the getMessage () method for each enumeration that delegates the implementation of your utility method)
- checking your localized files (your unit tests can loop in each language of the code and files and find all unsurpassed values)
- error level function (we use the same levels as for logging: fatal, errors, warnings, therefore logical decisions are very easily implemented!).
- To facilitate the search for the corresponding error by other developers, we use several enumerations (possibly in the same package), classifying errors according to their technical or functional domain.
To ask your two problems:
- To add, you only need to add the instance to the enumeration and the message in the localization file (but the tests can catch later if you forget).
- When classifying in several enumerations, and possibly in javadoc, they are guided by the correct error.
source share