Class 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.

    • Constructor Detail

      • DefaultExceptionPolicyStrategy

        public DefaultExceptionPolicyStrategy()
    • Method Detail

      • 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