Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: CAMEL-102

...

Here if the processing of seda:inputA or seda:inputB cause a ValidationException to be thrown (such as due to the XSD validation of the Validation component or the Relax NG Compact syntax validation of the Jing component), then the message will be sent to activemq:validationFailed queue.

...

Catching multiple exceptions

Available as of Camel 1.5

In Camel 1.5 the exception clauses has been renamed to onException and it also supports multiple exception classes:

...

Code Block
xml
xml
    <bean id="myRedeliveryPolicy" class="org.apache.camel.processor.RedeliveryPolicy">
        <property name="maximumRedeliveries" value="${myprop.max}"/>
    </bean>

     <onException>
         <!-- you can define multiple exceptions just adding more exception elements as show below -->
         <exception>com.mycompany.MyFirstException</exception>
         <exception>com.mycompany.MySecondException</exception>

         <!-- here we reference our redelivy policy defined above -->
         <redeliveryPolicy ref="myRedeliveryPolicy"/>
     </onException>

Using fine grained selection using onWhen predicate

Available as of Camel 1.5.1 or later

...

In the sample above we have two onException's defined. The first has an onWhen expression attached to only trigger if the message has a header with the key user that is not null. If so this clause is selected and is handling the thrown exception. The 2nd clause is a for coarse gained selection to select the same exception being thrown but when the expression is evaluated to false. Notice: this is not required, if the 2nd clause is omitted, then the default error handler will kick in.

Using fine grained retry using retryUntil predicate

Available as of Camel 2.0

When you need fine grained control for determining if an exchange should be retried or not you can use the retryUntil predicate. Camel will redeliver until the predicate returns false.
This is demonstrated in the sample below:

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

Where the bean myRetryHandler is computing if we should retry or not:

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

See also

The Error Handler for the general error handling documentation
The Dead Letter Channel for further details.
The Transactional Client for transactional behavior