Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This is the new default error handler in Camel 2.0 onwards.TODO: bla bla

This error handler have a limited set of features. You can use the Exception Clause to catch exceptions and De Tour exchanges. Redeliveries is not supports, so any redelivery configuration on an Exception Clause will not apply.

By default any exception thrown during routing will be propagated back to the caller and the Exchange ends immediately. However you can use the Exception Clause to catch a given exception and lower the exception by marking it as handled. If so the exception will not be sent back to the caller and the Exchange continues to be routed.

Example

In this route below, any exception thrown in eg the validateOrder bean will be propagated back to the caller, and its the jetty endpoint. It will return a HTTP error message back to the client.

Code Block
java
java

from("jetty:http://localhost/myservice/order").to("bean:validateOrder").to("jms:queue:order");

We can add a onException in case we want to catch certains exceptions and route them differently, for instance to catch a ValidationException and return a fixed response to the caller.

Code Block
java
java

onException(ValidationException.class).handled(true).transform(body(constant("INVALID ORDER")));

from("jetty:http://localhost/myservice/order").to("bean:validateOrder").to("jms:queue:order");

When the ValidationException is thrown from the validate order bean it is intercepted by the DefaultErrorHandler and it let the onException(ValidationException.class handle it so the Exchange is routed to this route and since we use handled(true) then the original exception is lowered (= cleared) and we transform the message into a fixed response that are returned to jetty endpoint that returns it to the original caller.

See Also