On Fri, Jun 6, 2014 at 11:46 AM, dritter <[email protected]> wrote: > Hello, > > I am analyzing the Exception handling capabilities of Apache Camel and might > have run into an inconsistency between the Java DSL and Blueprint, when > using onException on a route-processor level. > > Due to several reasons, I do not want to use the doTry/doCatch handling, but > the onException constructs. For instance, to handle any exception from > "processor1" in the following route in Java DSL an onException statement is > used that handles (handled==true) the exception. > > from("direct:in") > .onException(IOException.class) > .handled(true) > .process(excProcessor) > .end() > .process(processor1) > > However, if there is a subsequent processor, e.g., "processor2", in the > route, which might throw IOExceptions, but shall not be handled using > "excProcessor", the following addition helps to "unregister" the handler for > subsequent processors: > > from("direct:in") > .onException(IOException.class) > .handled(true) > .process(excProcessor) > .end() > .process(processor1) > *.onException(Exception.class) > .handled(false) > .end() > .process(processor2)* > > Maybe that behavior is not intended (?), but if "processor2" throws an > IOException, the first onException clause with the "excProcessor" does not > get invoked. >
You should not do (*) as its not intended. You set onException either at context level, or at route level. And for route level you configure this in the start. Camel 3 will change the DSL to restrict this wrongdoing you are with (*). > How can the same behavior be ensured when using the Blueprint DSL? Directly > translated, the code from above would like the following in Blueprint. > However, now, the IOException is caught by the defined handler. The > "de-registration" does not happen. > > <camelContext> > <route> > <from uri="direct:in"/> > <onException> > <exception>IOException</exception> > <handled> > <constant>true</constant> > > ... > </handled> > </onException> > > > ... > *<onException> > <exception>java.lang.Exception</exception> > <handled> > <constant>false</constant> > </handled> > </onException>* > > > ... > <to uri="direct:out"/> > </route> > </camelContext> > > Do you know a way how to ensure the same behavior? Thank you in advance. > > Best regards, > Daniel Ritter > > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/Try-Catch-like-onException-with-Blueprint-DSL-tp5751973.html > Sent from the Camel - Users mailing list archive at Nabble.com. -- Claus Ibsen ----------------- Red Hat, Inc. Email: [email protected] Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen hawtio: http://hawt.io/ fabric8: http://fabric8.io/
