简体   繁体   中英

Apache Camel - onWhen() predicate cannot retrieve EXCEPTION_CAUGHT, but in the processor it is present

I cannot access caught exception in onWhen(predicate) after doCatch() , but I can see it in the processor in doCatch() . This is inconvenient when I want to define a finer-grained predicate in onWhen() .

doCatch(ProcessingException.class).onWhen(predicate) // <<< here I cannot see exception
    .process(MyProcessor.class) // <<< here I see exception
    ...

exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class) returns null in the predicate. I see exchange.getAllProperties() does not contain the key.

Any idea? Is it by design? Now I cannot decide enter catch processor or not depending on exception message.

I was struggling with this until I read the method's documentation:

Sets an additional predicate that should be true before the onException is triggered.

To be used for fine grained controlling whether a thrown exception should be intercepted by this exception typeor not.

That may explain why you are able to see the exception details in the processor and not in the "onWhen" clause.

Hope it helps.

Regards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM