A simpler solution would be to use exceptions .
If an error occurs that will be displayed by the user, enter a special type of exception - possibly with the name UserError . The exception must contain the text of the error message when it is thrown. These errors are functions that provide users with useful information (i.e., they tried to delete something that was not there, which could happen when they have several browsers open, etc.).
eg:.
throw new UserError("That object no longer exists.");
If an error occurs that you want to hide from the user, enter another type of exception, possibly called InternalError . You would like to log this and let the program continue to work, so the specific error is hidden from the user. If this prevents something, you may need to generate a generic error message. These will be errors, and you want to fix them as soon as possible.
eg:.
throw new InternalError("Failed to connect to remote service");
All error messages can be stored (hard-coded) in the source where the exception is thrown. This is not necessarily a bad design β if you use a tool like gettext , you can easily translate all of these messages.
Fragsworth
source share