Maybe someone else can explain the reasoning for this behavior, but what's
happening is:

your errorHandler is handling the exception in route 2, but it doesn't see
any exception handlers (none declared on the immediate route, and none
globally defined).

so it just tries redelivery, marks it as "FAILURE_HANDLED". When the first
route gets the exchange, it will decide what to do with it... and since the
route first handling the error marked it as "FAILURE_HANDLED" the first
route doesn't try to do anything with it and propagate the exception back
up.

To get the behavior you're looking for, move the onException clause to be
global.

HTH


On Thu, Oct 17, 2013 at 3:33 PM, Bilgin Ibryam <bibr...@gmail.com> wrote:

> Hi Camel riders,
>
> I'm trying to figure out why onException is not triggerd in the following
> route. The solution I found is to use try-catch instead, but I'd prefer to
> have it work only with errorHandler and onException
>
>
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.test.junit4.CamelTestSupport;
> import org.junit.Test;
>
> public class ErrorTest extends CamelTestSupport {
>
>     @Test
>     public void testErrorIsThrown() throws Exception {
>
>         getMockEndpoint("mock:foundException").expectedMessageCount(1);
>
>         try {
>             template.sendBody("direct:start", "test");
>             fail("Propagate exception back to consumer");
>         } catch (Exception e) {
>         }
>         assertMockEndpointsSatisfied();
>     }
>
>     @Override
>     protected RouteBuilder createRouteBuilder() {
>         return new RouteBuilder() {
>             public void configure() {
>
>                 from("direct:start")
>                         .to("direct:internal")
>                             .onException(Exception.class)
>                             .to("mock:foundException");
>
>                 from("direct:internal")
>
> .errorHandler(defaultErrorHandler().maximumRedeliveries(2))
>                         .throwException(new RuntimeException())
>                         .to("mock:never");
>             }
>         };
>     }
> }
>
>
>
> --
> Bilgin Ibryam
>
> Apache Camel & Apache OFBiz committer
> Blog: ofbizian.com
> Twitter: @bibryam <https://twitter.com/bibryam>
>
> Author of Instant Apache Camel Message Routing
> http://www.amazon.com/dp/1783283475
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta

Reply via email to