Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Not A Bug
-
3.14.7
-
None
-
None
-
Unknown
Description
Camel Does not continue routing with a doTry..doCatch..end block with direct component with a onException clause defined in it.
I have created two routes namely, MainRoute and childRoute.
The ChildRoute consists of an onExceptionBlock, with "handled(true)" clause.
when an exception occurs in the childRoute, the onExceptionBlock executes and the chlidRoute execution stops. However, the flow doesn't continue on the mainRoute.
Camel DSL for the two routes:
from("timer://runOnce?repeatCount=1&delay=1000")
.id("MainRoute")
.onException(Exception.class)
.setBody(constant("ExceptionBLock"))
.to("log://error")
.handled(true)
.end()
.setHeader("routeLocation", constant("MainRoute"))
.setBody(constant("MainRoute"))
.to("log://main")
.doTry()
.to("direct://childRoute")
.doCatch(Exception.class)
.to("log://ExceptionCatchBlock")
.end()
.to("log://afterTryCatch")
.end();
------------------
from("direct://childRoute")
.id("ExceptionRoute")
.onException(Exception.class)
.useOriginalMessage()
.handled(true)
.setBody(constant("Child Exception Block"))
.to("log://childExceptionSubProcess")
.end()
.setHeader("routeLocation", constant("exceptionRoute"))
.setBody(constant("Exception Route"))
.to("log://beforeException")
.throwException(new RuntimeException("A runtime exception"))
.to("log://afterException")
.end();
Output:
2023-06-13 16:30:20.876 INFO 3500 — [timer://runOnce] main : Exchange[ExchangePattern: InOnly, BodyType: String, Body: MainRoute]
2023-06-13 16:30:20.880 INFO 3500 — [timer://runOnce] beforeException : Exchange[ExchangePattern: InOnly, BodyType: String, Body: Exception Route]
2023-06-13 16:30:20.883 INFO 3500 — [timer://runOnce] childExceptionSubProcess : Exchange[ExchangePattern: InOnly, BodyType: String, Body: Child Exception Block]
In the above routes, when the exception occurred in the childRoute, the onException block in childRoute executes, however, the .to("log://afterException") of the mainRoute doesn't execute.
As per the documentation, the doTry..doCatch block mimic the Java, try..catch block.
Here the routing breaks on the mainRoute. Contrary to the try..catch of java, where exception handling inside a called method doesn't affect the caller.