簡體   English   中英

確定哪個類型的異常是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被父類包圍,如ExceptionThrowable那么使用getCause()

if (throwable.getCause() instanceof CertificateException)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM