Versions Compared

Key

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

...

Wiki Markup
{snippet:id=e4|lang=java|url=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ErrorHandlerTest.java}

ExceptionPolicyStrategy (New feature in Camel 1.4)

ExceptionPolicyStrategy is a strategy for resolving which rule (ExceptionType) should handle the given thrown exception.

DeadLetterChannel supports pluggable strategies for resolving how exceptions should be handled. It is common to how different strategies for different types of exceptions. For instance network and IO related exceptions is more prone for network outages so the redeliver policy could have a higher attempts, timeouts etc. Where as a NullPointerException is typically a programming error so these kind of exception is severe and should not be redelivered. Camel uses a default strategy DefaultExceptionPolicyStrategy that applies the following rules:

  • The exception type must be configured with an Exception that is an instance of the thrown exception
  • If the exception type has exactly the thrown exception then its selected
  • Otherwise the type that has an exception that is super of the thrown exception is selected (recurring up the exception hierarchy)

The example below illustrates a common exception handling configuration in Camel:

Wiki Markup
{snippet:id=exceptionBuilder1|lang=java|url=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ExceptionBuilderTest.java}

Here we have configured the handling of exceptions into three categories:

  • NullPointerException (for special handling of these hard to track down bugs)
  • IOException (for IO and network related issues we can attempt many times)
  • Exception (fallback exception handling for all other kind of exceptions)

Camel will with the default strategy try to select the best suited category from above for any thrown exception.
So if a java.net.ScoketException is thrown then the IOException category will handle it. If a NumberFormatException or CamelExchangeException is thrown it is handled by the general purpose Exception category.

Camel supports pluggable exception policy strategies. See Error Handler for such details.

Include Page
CAMEL:Using This Pattern
CAMEL:Using This Pattern