Apache Camel – Error Handing

Error handlers in Camel
In the previous section you learned that Camel regards all exceptions as recoverable
and stores them on the exchange using the setException(Throwable cause)
method. This means error handlers in Camel will only react to exceptions set on the
exchange. By default, they won’t react if an irrecoverable error has been set as a fault
message. The rule of thumb is that error handlers in Camel only trigger when
exchange.getException() != null.

Using exception policies
Exception policies are used to intercept and handle specific exceptions in particular
ways. For example, exception policies can influence, at runtime, the redelivery policies
the error handler is using. They can also handle an exception or even detour
a message.

Below shows how you can make the code compile and work at runtime as you
would expect with a try … catch block.

public void configure() {
.process(new ValidateOrderId())
.process(new GenerateResponse());
.process(new GenerateFailureResponse())


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.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s