Best practice for storage and retrieval of error messages.

Posted by ferrari fan on Stack Overflow See other posts from Stack Overflow or by ferrari fan
Published on 2010-03-08T17:16:48Z Indexed on 2010/03/08 17:21 UTC
Read the original article Hit count: 303

Filed under:
|
|
|

What is a best practice for storing user messages in a configuration file and then retrieving them for certain events throughout an application?

I was thinking of having 1 single configuration file with entries such as

REQUIRED_FIELD = {0} is a required field
INVALID_FORMAT = The format for {0} is {1}

etc. and then calling them from a class that would be something like this

public class UIMessages {
    public static final String REQUIRED_FIELD = "REQUIRED_FIELD";
    public static final String INVALID_FORMAT = "INVALID_FORMAT";

    static {
        // load configuration file into a "Properties" object
    }
    public static String getMessage(String messageKey) {
        // 
        return properties.getProperty(messageKey);
    }
}

Is this the right way to approach this problem or is there some de-facto standard already in place?

© Stack Overflow or respective owner

Related posts about java

Related posts about ui