[英]throw Throwable in Stream -> "Unhandled exception type Throwable"
[英]Determine which type of exception is the throwable
這是目前正在運行的代碼:
.whenComplete((r, throwable) -> {
if (throwable != null) {
logger.error("exception");
}
});
是否有可能做這樣的事情,以確定throwable是否是某種類型的異常?
.whenComplete((r, throwable) -> {
if (throwable == CertificateException) {
logger.error("cert exception");
}
});
使用instanceof
關鍵字來查找類型
if (throwable instanceof CertificateException)
如果throwable被父類包圍,如Exception
或Throwable
那么使用getCause()
if (throwable.getCause() instanceof CertificateException)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.