I am reading properties file in the Dynamic web application as follows :
try
{
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("messages.properties"));
}
catch(IOException e){
e.printStackTrace();
throw new AxisFault(e.getMessage());
}
It’s loading the messages properly without any issue and I copied it into WEB-INF/classes directory. Now, if I delete the file and trying to run the web application it’s throwing NullPointerException, instead of catching and throwing Axis Fault exception.
How can I catch the exception if the message.properties file doesn’t exist ?
NullPointerException is a runtime exception so the compiler won’t warn you that you don’t catch it. And it is not a type of IOException so it is not caught by your catch block.
You can do:
or to catch all other exceptions