There are two doTry blocks in your camel route which could confuse the compiler, as Camel Java DSL is not good at blocks. You can work around the issue by using the direct endpoint to avoid using doTry inside of doCatch just like this
from("direct:start") .doTry() .setBody(simple("doTry")) .to("stream:out") .doCatch(Exception.class) .setBody(simple("doCatch")) .to("stream:out") .to("direct:anotherDoTry") .doFinally() .setBody(simple("doFinally")) .to("stream:out") .doTry() .setBody(simple("doTry in doFinally")) .to("stream:out") .doCatch(Exception.class) .setBody(simple("doCatch in doFinally")) .to("stream:out") .end() .stop() .endDoTry(); from("direct:anotherDoTry") .doTry() .setBody(simple("doTry in doCatch")) .to("stream:out") .doCatch(Exception.class) .setBody(simple("doCatch in doCatch")) .to("stream:out") .end(); -- Willem Jiang Red Hat, Inc. Web: http://www.redhat.com Blog: http://willemjiang.blogspot.com (English) http://jnn.iteye.com (Chinese) Twitter: willemjiang Weibo: 姜宁willem On June 17, 2014 at 9:06:08 PM, james555 (luke...@gmx.net) wrote: > Hello, > > I need to use nested catch-blocks in my project like the following: > > from("direct:start") > .doTry() > .setBody(simple("doTry")) > .to("stream:out") > .doCatch(Exception.class) > .setBody(simple("doCatch")) > .to("stream:out") > .doTry() > .setBody(simple("doTry in doCatch")) > .to("stream:out") > .doCatch(Exception.class) > .setBody(simple("doCatch in doCatch")) > .to("stream:out") > .end() > .doFinally() > .setBody(simple("doFinally")) > .to("stream:out") > .doTry() > .setBody(simple("doTry in doFinally")) > .to("stream:out") > .doCatch(Exception.class) > .setBody(simple("doCatch in doFinally")) > .to("stream:out") > .end() > .stop() > .endDoTry(); > > > Compiler says: the method doFinally() is undefined for the type > ProcessorDefinition so Eclipse suggests ("add cast to > method receiver") following: > > > > ((TryDefinition) from("direct:start") > .doTry() > .setBody(simple("doTry")) > .to("stream:out") > .doCatch(Exception.class) > .setBody(simple("doCatch")) > .to("stream:out") > .doTry() > .setBody(simple("doTry in doCatch")) > .to("stream:out") > .doCatch(Exception.class) > .setBody(simple("doCatch in doCatch")) > .to("stream:out") > .end() > ) > .doFinally() > .setBody(simple("doFinally")) > .to("stream:out") > .doTry() > .setBody(simple("doTry in doFinally")) > .to("stream:out") > .doCatch(Exception.class) > .setBody(simple("doCatch in doFinally")) > .to("stream:out") > .end() > .stop() > .endDoTry(); > > > but then at runtime I get: > > java.lang.ClassCastException: org.apache.camel.model.CatchDefinition cannot > be cast to org.apache.camel.model.TryDefinition > > > Whats wrong here, I can't see a syntax error ? Is it a bug ? > > thanks for any advice > > james > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/nested-catch-blocks-in-doCatch-and-doFinally-tp5752429.html > > Sent from the Camel - Users mailing list archive at Nabble.com. >