M
Manish Hatwalne
I have a legacy code (and I can't change this part) which uses construct
such as -
try{
doSomething();
.........
}catch(Exception e){
throw new CustomException(e);
}
Now while using call to this method, I have to handle this exception, and I
need to write specific message meant for an exception wrapped by this
CustomException. So I write -
try{
callThisMethod();
}catch(CustomException ce){
Throwable t = ce.getCause() ; //what should I use here??
if(t instanceof SomeException){
/// appropriate message
}
}
My problem is how do I get the exception wrapped by this CustomException? I
thought getCause() will return me that, but it returns CustomException. How
do I get the wrapped exception? It could range from NoRouteToHostException
to a NullPointerException, and I need to have my messages based on that. How
do I do this?
TIA,
- Manish
such as -
try{
doSomething();
.........
}catch(Exception e){
throw new CustomException(e);
}
Now while using call to this method, I have to handle this exception, and I
need to write specific message meant for an exception wrapped by this
CustomException. So I write -
try{
callThisMethod();
}catch(CustomException ce){
Throwable t = ce.getCause() ; //what should I use here??
if(t instanceof SomeException){
/// appropriate message
}
}
My problem is how do I get the exception wrapped by this CustomException? I
thought getCause() will return me that, but it returns CustomException. How
do I get the wrapped exception? It could range from NoRouteToHostException
to a NullPointerException, and I need to have my messages based on that. How
do I do this?
TIA,
- Manish