重複の可能性:
throws 宣言を追加せずに例外をスローする方法はありますか?
メソッドが既に定義されていて句がない場合に、カプセル化Exception
して別のメソッドに再スローする方法があるのだろうか。Exception
throws
例 (JMSonMessage
メソッドを使用):
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
では、どうすれば自分のコードでカプセル化してディスパッチできますか? 方法はありますか?ありがとう