You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Claus Ibsen (Jira)" <ji...@apache.org> on 2023/06/13 12:17:00 UTC
[jira] [Resolved] (CAMEL-19441) Camel does not continue routing after doTry..doCatch..end block in case of Direct Component.
[ https://issues.apache.org/jira/browse/CAMEL-19441?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Claus Ibsen resolved CAMEL-19441.
---------------------------------
Resolution: Not A Bug
The child route handles(true) the exception so there is no exception from the outer route point of view
> Camel does not continue routing after doTry..doCatch..end block in case of Direct Component.
> --------------------------------------------------------------------------------------------
>
> Key: CAMEL-19441
> URL: https://issues.apache.org/jira/browse/CAMEL-19441
> Project: Camel
> Issue Type: Bug
> Components: camel-core, camel-core-api
> Affects Versions: 3.14.7
> Reporter: Harish Annamalai
> Priority: Major
>
> 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 {color:#ff0000}.to("log://afterException") of the mainRoute {color}{color:#172b4d}{{doesn't execute.}}{color}}}
> {color:#172b4d}As per the documentation, the doTry..doCatch block mimic the Java, try..catch block.{color}
> {color:#172b4d}{{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.}}{color}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)