가능한 중복 :
Is there a way to throw an exception without adding the throws declaration?어떻게 예외를 되돌릴 수 있습니까?
Exception
을 캡슐화 및 방법이 이미 정의되어 throws
조항이없는 경우 다른 Exception
에서 그것을 다시 발생 할 수있는 방법이 있는지 궁금.
예 (JMS와 onMessage
방법) :
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
}
}
}
그래서, 어떻게하십시오 캡슐화 내 코드에 CustomException
를 전달할 수 있습니다
예입니다. 죄송합니다 –