別の例外にネストされた例外をキャッチしたいです。現在は次のようにしています:
} catch (RemoteAccessException e) {
if (e != null && e.getCause() != null && e.getCause().getCause() != null) {
MyException etrp = (MyException) e.getCause().getCause();
...
} else {
throw new IllegalStateException("Error at calling service 'service'");
}
}
これをもっと効率的かつエレガントに行う方法はありますか?
ベストアンサー1
の例外ユーティリティ#getRootCause()このような状況では、この方法が非常に役立ちます。