I have a code where I access keystore. When my password is wrong I get an exception of type UnrecoverableKeyException. So I wrote my code as :
try {
InputStream f = new FileInputStream("<location to file>")
keyStore.load( f , passwords );
} catch(UnrecoverableKeyException e){
log.error("")
}
But that doesn’t catch the exception. So in my catch block, I changed my code to :
catch(Exception e)
{
log.error(e.getClass(),e)
}
which catch the exception and prints the class type is of class java.io.IOException. But why does in the first place I get an message that exception is of UnrecoverableKeyException?
Whats happening actually?
Thanks in advance.
The Javadoc for
KeyStore.loadstates that it can throw anIOException, and also:This means what you catch is actually an
IOExceptionbute.getCause()would be anUnrecoverableKeyException. When the stack trace gets printed, you would see all causes in the chain, which perhaps led you to think it was anUnrecoverableKeyException.