开发者

Fetch custom exception from the exchange

开发者 https://www.devze.com 2023-03-21 20:25 出处:网络
I have declared my CustomException class. When the onException() catches it , it goes to the processor I defined :

I have declared my CustomException class. When the onException() catches it , it goes to the processor I defined :

onException(classOf[CustomException]).process(doSmth)

So far so good . The issue that I need into the processor to check if the exception is of type "CustomException" or not

when I write :

def process(exchange: Exchange) = { val exception: CustomException= exchange.getProperty(Exchange.EXCEPTION_CAUGHT, classOf[CustomException])

I got null

But when I write :

def process(exchange: Exchange) = {
    val exception: Exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, classOf[Exception])

I got my exception object

How could I check which typ开发者_JAVA百科e of exception is thrown into the processor !


in Java DSL, this works...

public void process(Exchange exch) throws Exception {
    Exception e = (Exception) exch.getProperty(Exchange.EXCEPTION_CAUGHT);
    if (e instanceof CustomException) {
        logger.info("custom exception");
    } else {
        logger.info("other excpetion");
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消