Class DefaultExceptionPolicyStrategy

java.lang.Object
org.apache.camel.processor.errorhandler.DefaultExceptionPolicyStrategy
All Implemented Interfaces:
ExceptionPolicyStrategy

public class DefaultExceptionPolicyStrategy extends Object implements ExceptionPolicyStrategy
The default strategy used in Camel to resolve the ExceptionPolicyKey that should handle the thrown exception.

Selection strategy:
This strategy applies the following rules:

  • Will walk the exception hierarchy from bottom upwards till the thrown exception, meaning that the most outer caused by is selected first, ending with the thrown exception itself. The method createExceptionIterable(Throwable) provides the Iterator used for the walking.
  • The exception type must be configured with an Exception that is an instance of the thrown exception, this is tested using the filter(ExceptionPolicyKey, Class, Throwable) method. By default the filter uses instanceof test.
  • If the exception type has exactly the thrown exception then its selected as its an exact match
  • Otherwise the type that has an exception that is the closest super of the thrown exception is selected (recurring up the exception hierarchy)

Fine grained matching:
If the ExceptionPolicyKey has a when defined with an expression the type is also matches against the current exchange using the matchesWhen(ExceptionPolicyKey, org.apache.camel.Exchange) method. This can be used to for more fine grained matching, so you can e.g. define multiple sets of exception types with the same exception class(es) but have a predicate attached to select which to select at runtime.

  • Field Details

  • Constructor Details

    • DefaultExceptionPolicyStrategy

      public DefaultExceptionPolicyStrategy()
  • Method Details

    • getExceptionPolicy

      public ExceptionPolicyKey getExceptionPolicy(Set<ExceptionPolicyKey> exceptionPolicies, org.apache.camel.Exchange exchange, Throwable exception)
      Description copied from interface: ExceptionPolicyStrategy
      Resolves the ExceptionPolicyKey that should handle the thrown exception.
      Specified by:
      getExceptionPolicy in interface ExceptionPolicyStrategy
      Parameters:
      exceptionPolicies - the configured exception policies to resolve from
      exchange - the exchange
      exception - the exception that was thrown
      Returns:
      the resolved exception type to handle this exception, null if none found.
    • filter

      protected boolean filter(ExceptionPolicyKey type, Class<?> exceptionClass, Throwable exception)
      Strategy to filter the given type exception class with the thrown exception
      Parameters:
      type - the exception type
      exceptionClass - the current exception class for testing
      exception - the thrown exception
      Returns:
      true if the to current exception class is a candidate, false to skip it.
    • matchesWhen

      protected boolean matchesWhen(ExceptionPolicyKey definition, org.apache.camel.Exchange exchange)
      Strategy method for matching the exception type with the current exchange.

      This default implementation will match as:

      • Always true if no when predicate on the exception type
      • Otherwise the when predicate is matches against the current exchange
      Parameters:
      definition - the exception definition
      exchange - the current Exchange
      Returns:
      true if matched, false otherwise.
    • createExceptionIterable

      protected Iterable<Throwable> createExceptionIterable(Throwable exception)
      Strategy method creating the iterator to walk the exception in the order Camel should use for find the ExceptionPolicyKey should be used.

      The default iterator will walk from the bottom upwards (the last caused by going upwards to the exception)

      Parameters:
      exception - the exception
      Returns:
      the list to iterate