Possible Duplicate:
Is there a way to throw an exception without adding the throws declaration?
I wonder if there is a way to encapsulate Exception
and rethrow it in another Exception
when method is already defined and don't have throws
clause.
An example (with JMS onMessage
method) :
public void onMessage(Message message) {
if(message instanceof ObjectMessage){
ObjectMessage objectMessage = (ObjectMessage)message;
try {
Object object = objectMessage.getObject();
} catch (JMSException e) {
throw new CustomException("blah blah", e); // ERROR HERE : Unhandled exception type CustomException
}
}
}
So, how can I encapsulate and dispatch CustomException
in my code please ? Is there a way ? Thanks