I have a route with doTry() - doCatch() pair for a specific route and onException() in general.
onException(Exception.class)
.handled(true)
.log(LoggingLevel.ERROR, "An error occurred: ${exception.stacktrace}")
.setBody(simple("${exception}"))
.setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500));
from("direct:mydirect")
.routeId("myRoute")
.doTry()
.to("direct:internalroute")
.doCatch(Exception.class)
.log(LoggingLevel.ERROR, "EXCEPTION: ${exception.stacktrace}")
.process(exceptionHandlerProcessor)
.setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500))
.marshal(new JsonDataFormat(JsonLibrary.Jackson))
.doFinally()
.log("FINALLY")
.endDoTry();
Internal route throws a plain java.lang.Exception
throw new Exception("Catch me if you can!");
I expected the exception to be caught in doCatch() and logging and pocessing operations to be executed. However, onException() is invoked instead.
Does onException() have a higher prority? In my understanding local catch is more prioritized.
P.S. Removing onException() makes doCatch() invoked. However I have reasons to keep both. Camel version is: org.apache.camel:camel-cxf:2.21.0.000033-fuse-000001-redhat-1