My application is communicating with a web client. If there is any exception raised in my application, we have to log it and send it back to the web client which will interpret the error code and error message.
Presently we have errorcodes and messages hardcoded for specific Exception situations. for example if I am not able to make a URLConnection, I will log an errorcode say 2020 and a corresponding message, and send it back to the web client as well.
There is an issue about hardcoding the message for a perticular situation. We are solving it be storing the codes and messages in a property file, so that it is possible to change the message for a perticular Exception condition if necessary without having to recompile.
Patrik Naughton's book recommends against using errorcodes, and JDK which is a fairly complex piece of code doesnt uses error codes, but has subclasses of Exception for specific situations.
My question is if it is really necessary to use error codes in
java application to keep track of different error conditions. If we write Subclasses of Exception to represent these error conditions, then does this amounts to hardcoding?I would appreciate answer from someone who has worked on c, because errorcodes are used in c,(there must be a reason for that practice).