Munni
Munni

Reputation: 79

Camel route specific onException not triggered

below is the code:

    <route id="StartMyRoute">
      <from uri="direct:StartMyRoute"/>
      <to uri="direct:myRoute2"/>
      <onException>
        <exception>SpecificException</exception>
            <to uri="direct:myRoute3"/>
      </onException>
    </route>

I was trying the same thing with Java DSL:

    from("direct:StartMyRoute")
                .routeId("StartMyRoute")
                .to("direct:myRoute2")
                .onException(SpecificException.class)
                .to("direct:myRoute3");

which didn't work but later I tried onException at the global scope which worked. I have some route specific functionality that should be executed in onException(...) handler so I can't use global scope.

Below is my code which has global scope:

    onException(SpecificException.class)
                .to("direct:myRoute3");

    from("direct:StartMyRoute")
                .routeId("StartMyRoute")
                .to("direct:myRoute2");

Can someone help me understand why route-specific onException(...) is not triggered?

Upvotes: 1

Views: 1447

Answers (2)

Munni
Munni

Reputation: 79

Got this solution working:

from("direct:StartMyRoute")
    .routeId("StartMyRoute")
    .onException(SpecificException.class)
    .to("direct:myRoute3")
    .end
    .to("direct:myRoute2");

Upvotes: 1

Hasan Birol
Hasan Birol

Reputation: 166

In generally you can catch all exception (filtering if condition)

onException(Exception.class)
  .process(new Processor() {
    public void process(Exchange exchange) throws Exception {
        if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) instanceof SpecialException.class) {
            // TODO something...
        }
    }).handled(true);

Upvotes: 0

Related Questions