Hello All,
Currently in our system, we have hardcoded a
String (tokens) to a static final instance variable and a new solution is proposed to read the string from a properties file instead.
Since our class would be called by sessionbean for every incoming request, we do not want to have the properties file reading functionality to be called for every request and hence I thought of writing a static method which reads the file for the first time the class is loaded. Something like below
Now the problem is readFile() method can throw an Exception, if it could not read the file or for something else and I can not catch the exception and swallow it. I need to throw the exception. But how can this be handled at the invocation at
private static final String str=readFile()
The other option, I have is to modify as
Is the second approach a better one than the first ? I'm inclining on the first approach, if I could find a way to tap the exception, as I'm doing what ever initiation to be done during class loading phase.