On Tue, Nov 10, 2009 at 11:19 AM, DRy <[email protected]> wrote:
>
> Hi,
>
> I think I've got it ...
>
> On my RouteBuilder-class (see below) I try to catch UnmarshalException in
> one and all other excpetions in the other onException call.
>
>
> onException(UnmarshalException.class)
> .useOriginalBody()
> .handled(true)
> .to("log:onException(UnmarshalException.class)?level=INFO")
> .end();
>
> onException(Exception.class)
> .useOriginalBody()
> .handled(true)
> .to("log:onException(Exception.class)?level=INFO")
> .end();
>
> from("activemq:publish?exchangePattern=InOnly&transacted=true")
> .routeId(Publish2CenterRouteBuilder.ROUTE_ID)
> .transacted()
> .process(new Publish2CenterProcessor())
> .multicast()
> .pipeline()
>
> .to("activemq:BonData?exchangePattern=InOnly&transacted=true")
> .end()
> .pipeline()
>
> .to("activemq:NonBonData?exchangePattern=InOnly&transacted=true")
> .end()
> .end()
> .end();
>
>
> In my processor/bean (Publish2CenterProcessor) if a UnmarshalException is
> thrown I use the constructor that put in a nested exception (in that case a
> XMLException from XMLBeans)!!
>
Can you show the entire hierarchy of this exception? I guess it could
contain also a caused exception which may be of type Exception or the
likes.
>
> throw new UnmarshalException("Could not unmarshal body to XML3!",
> exception);
>
>
> As descriped in http://camel.apache.org/exception-clause.html camel will
> "start from the bottom (nested caused by) and recursive up in the exception
> hierarchy to find the first matching onException clause". In my case the
> nested exception (XMLException) will be testet against UnmarshalException
> (no match) and next against Exception (match). So the intended
> UnmarshalException will endup in onException(Exception.class).
>
I guess Exception is too generic and we should take special care for
this one and always wind up the entire hierarchy
to see if there is an 100% match such as the UnmarshalException in your case.
> Why does camel test "from the bottom (nested caused by) and recursive up in
> the exception hierarchy" and not vise versa ... ?
>
Because the real exception is in the bottom. The middle exceptions is
most often just wrapper exceptions of some sort.
You can write you custom exception policy using ExceptionPolicyStrategy.
>
> ... DRy
>
> --
> View this message in context:
> http://old.nabble.com/Exception-handling-...-onException-tp26215607p26281107.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus