Answer the question
In order to leave comments, you need to log in
Should I handle errors when using ResourceBundle?
Hello. I took a ready-made piece of code that will read the property file with the database config.
public class DBResManager {
private final String CONFIG_PATH = "res.dbconfig";
private final static DBResManager instance = new DBResManager();
private ResourceBundle dbConfig = ResourceBundle.getBundle(CONFIG_PATH);
private DBResManager() {
}
public static DBResManager getInstance() {
return instance;
}
public String getValue(String key) {
return dbConfig.getString(key);
}
}
Answer the question
In order to leave comments, you need to log in
Properties files are internal application settings (variables). They are not edited from the outside, which means they must always contain correct data. If the properies file does not contain the key that the application requests, then this is either an incorrect file or errors in the program. It is better to exclude this at the development / testing stage, for which it is best to throw an exception.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question