这是当前正在运行的代码:
.whenComplete((r, throwable) -> {
if (throwable != null) {
logger.error("exception");
}
});
是否可以执行类似的操作来确定throwable是否是某种异常类型?
.whenComplete((r, throwable) -> {
if (throwable == CertificateException) {
logger.error("cert exception");
}
});
答案 0 :(得分:3)
使用instanceof
关键字查找类型
if (throwable instanceof CertificateException)
如果throwable与Exception
或Throwable
之类的父级包裹在一起,则使用getCause()
if (throwable.getCause() instanceof CertificateException)