I have a variable to initialize that is coming from a class with exception.
So if I do something like ConfigurationProvider reader = configurationReader.configurationProvider(), the .configurationProvider() part shows the red line telling the exception is unhandled in IntelliJ.
So I tried catching it inside the try/catch block like the following:
private String getConfigValue(ConfigurationProviderConfiguration configurationReader, String configName) {
String value = null;
ConfigurationProvider reader;
try {
reader = configurationReader.configurationProvider();
} catch (Exception e){
e.printStackTrace();
}
Properties config = reader.getConfiguration(configName); //Now, there is a red line under reader saying the variable might not have been initialized
if (config == null) {
LOGGER.warn("The configuration for " + configName + " cannot be found.");
}else{
value = config.getValue();
if (value == null) {
LOGGER.warn("The configuration for " + configName + " cannot be found.");
}
}
return value;
}
Now as you can see in the comment, there is a red line under reader saying the variable is not initialized. I understand why the compiler is complaining since it may skip the try and go to the catch block. I would try deleting catch block but I also can't do that since I have to handle the exception. What can I do in this case? Any help would be greatly appreciated.
ConfigurationProvider reader = null;