Apache Camel: errorHandler vs onException?

user1768830 picture user1768830 · Jun 27, 2013 · Viewed 17.2k times · Source

What's the difference between:

<camel:errorHandler id="deadLetterErrorHandler" type="DeadLetterChannel" 
        deadLetterUri="log:dead">

<camel:camelContext errorHandlerRef="deadLetterErrorHandler">
    ...
</camel:camelContext>

And:

<onException>
    ...
</onException>

According to this article, using them both in conjunction is a "powerful combination". How so? What roles do they each individual assume, and how do they complement each other?

Answer

Keith picture Keith · Jun 27, 2013

The errorHandler is used to handle any uncaught Exception that gets thrown during the routing and processing of a message. Conversely, onException is used to handle specific Exception types when they are thrown. Check out this article to see how to use onException.