You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Jose <ja...@gmail.com> on 2014/03/10 16:46:49 UTC

Nested doTry-doCatch blocks

Is it possible to have nested doTry-doCatch blocks? If so, how the inner
block should be ended?

For example:

.doTry()
     ....
     .doTry()
          ....
      .doCatch()
          ....
      ..end()
*.doCatch()*
     ....
.end()

This code does not compile. I get "Compilation error The method
doCatch(Class<Exception>) is undefined for the type   
ProcessorDefinition<capture#1-of ?>" in the second "doCatch".

Thank you very much.

Jose



--
View this message in context: http://camel.465427.n5.nabble.com/Nested-doTry-doCatch-blocks-tp5748561.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Nested doTry-doCatch blocks

Posted by Bart Horré <ba...@anova.be>.
Hi,

try to simplify your route by using direct endpoints.
The ChoiceProcessor tends to behave strangely when the route gets more
complex.

.from()
     ...
     .doTry()
          ...
          .log(level.INFO, log, "Reaches point 1.")
     .endDoTry()
     .doCatch(MyHttpException.class)
          ...
          .choice()
               .when()
                   .to("direct:a")
               .otherwise()
                    .to("direct:b")
          .end()
          .stop()
     .end()
     .log(level.INFO, log, "Reaches point 2.")
.end();

Bart Horré
Anova r&d bvba

On Mon, Jun 12, 2017 at 11:54 PM, stalbot <st...@ahold.com> wrote:

> I ran into this today.  I have a route with doTry/doCatch, where in the
> doCatch there is a choice()when()otherwise() block.  The code never reaches
> "point 2" for me, even when MyHttpException is not thrown.
>
> .from()
>      ...
>      .doTry()
>           ...
>           .log(level.INFO, log, "Reaches point 1.")
>      .endDoTry()
>      .doCatch(MyHttpException.class)
>           ...
>           .choice()
>                .when()
>                     ...
>                .otherwise()
>                     ...
>           .end()
>           .stop()
>      .end()
>      .log(level.INFO, log, "Reaches point 2.")
> .end();
>
> In the documentation doTry/doCatch/doFinally is always at the end of the
> route, so I can't tell how to end that block and have code after it (i.e.:
> point 2).
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.
> com/Nested-doTry-doCatch-blocks-tp5748561p5803329.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Nested doTry-doCatch blocks

Posted by stalbot <st...@ahold.com>.
I ran into this today.  I have a route with doTry/doCatch, where in the
doCatch there is a choice()when()otherwise() block.  The code never reaches
"point 2" for me, even when MyHttpException is not thrown.

.from()
     ...
     .doTry()
          ...
          .log(level.INFO, log, "Reaches point 1.")
     .endDoTry()
     .doCatch(MyHttpException.class)
          ...
          .choice()
               .when()
                    ...
               .otherwise()
                    ...
          .end()
          .stop()
     .end()
     .log(level.INFO, log, "Reaches point 2.")
.end();

In the documentation doTry/doCatch/doFinally is always at the end of the
route, so I can't tell how to end that block and have code after it (i.e.:
point 2).



--
View this message in context: http://camel.465427.n5.nabble.com/Nested-doTry-doCatch-blocks-tp5748561p5803329.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Nested doTry-doCatch blocks

Posted by Jose <ja...@gmail.com>.
Hi Claus,

Thanks for you response.

I can only see endDoTry(), not endDoCatch(). 

Should I use endDoTry() to end the inner doTry-doCatch block?

I am using Camel 2.11.0.

Thank you.

Jose





--
View this message in context: http://camel.465427.n5.nabble.com/Nested-doTry-doCatch-blocks-tp5748561p5748640.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Nested doTry-doCatch blocks

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Yeah you can do that though its not as often seen in use.

See this FAQ
https://camel.apache.org/why-can-i-not-use-when-or-otherwise-in-a-java-camel-route.html

When using java dsl you may need to use endXXX to make the compiler happy.

On Mon, Mar 10, 2014 at 4:46 PM, Jose <ja...@gmail.com> wrote:
> Is it possible to have nested doTry-doCatch blocks? If so, how the inner
> block should be ended?
>
> For example:
>
> .doTry()
>      ....
>      .doTry()
>           ....
>       .doCatch()
>           ....
>       ..end()
> *.doCatch()*
>      ....
> .end()
>
> This code does not compile. I get "Compilation error The method
> doCatch(Class<Exception>) is undefined for the type
> ProcessorDefinition<capture#1-of ?>" in the second "doCatch".
>
> Thank you very much.
>
> Jose
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Nested-doTry-doCatch-blocks-tp5748561.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Make your Camel applications look hawt, try: http://hawt.io