Versions Compared

Key

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

...

Available as of Camel 1.5

Tip
titleContinued

See also the section Handle and continue exceptions below

Using onException to handle known exceptions is a very powerful feature in Camel. However prior to Camel 1.5 you could not mark the exception as being handled, so the caller would still receive the caused exception as a response. In Camel 1.5 you can now change this behavior with the new handle DSL. The handle is a Predicate that is overloaded to accept three types of parameters:

...

Wiki Markup
{snippet:id=e3|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionHandleAndTransformTest.java}

Handle and continue exceptions

Available as of Camel 2.3

In Camel 2.3 we introduced a new option continued which allows you to both handle and continue routing in the original route as if the exception did not occur.

For instance to just ignore and continue if the IDontCareException was thrown we can do this:

Code Block

  onException(IDontCareException).continued(true);

You can maybe compare continued with a having a try ... catch block around each step and then just ignore the exception.
Using continued makes it easier in Camel as you otherwise had to use Try Catch Finally style for this kind of use case.

Example using continued

In this route below we want to do special handling of all IllegalArgumentException as we just want to continue routing.

Wiki Markup
{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionContinueTest.java}

And the same example in Spring XML:

Wiki Markup
{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/OnExceptionContinueTest.xml}

What is the difference between handled and continued?

If handled is true, then the thrown exception will be handled and Camel will not continue routing in the original route, but break out. However you can configure a route in the onException which will be used instead. You use this route if you need to create some custom response message back to the caller, or do any other processing because that exception was thrown.

If continued is true, then Camel will catch the exception and in fact just ignore it and continue routing in the original route. However if you have a route configured in the onException it will route that route first, before it will continue routing in the original route.

Using useOriginalMessage

Available as of Camel 2.0
The option useOriginalMessage is used for routing the original input body instead of the current body that potential is modified during routing.

...