假设我捕获了一个 AppException
类型的异常,但我只想在该异常具有 StreamException
类型的嵌套异常时对该异常执行某些操作。
if (e instanceof AppException)
{
// only handle exception if it contains a
// nested exception of type 'StreamException'
如何检查嵌套的 StreamException
?
最佳答案
做:if (e instanceof AppException and e.getCause() instanceof StreamException)
.
关于java - 您如何检查异常的类型以及嵌套异常的类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6479288/