...
Exception clauses is scoped as either:
- global
- or route specific
Where the global are the simplest and most easy to understand. In the advanced section we dig into the route specific and even combining them. However
...
Camel uses DefaultExceptionPolicyStrategy
to determine a strategy how an exception being thrown should be handled by which onException
clause. The strategy is:
- the order in which the
onException
is configured takes precedence. Camel will test from first...last defined. - Camel will start from the bottom (nested caused by) and recursive up in the exception hierarchy to find the first matching
onException
clause instanceof
test is used for testing the given exception with theonException
clause defined exception list. An exactinstanceof
match will always be used, otherwise theonException
clause that has an exception that is the closets super of the thrown exception is selected (recurring up the exception hierarchy)
This is best illustrated with an exception:
...
Using onException to handle known exceptions is a very powerful feature in Camel. However prior to Camel 1.5 you could not mark the exception as being handled, so the caller would still receive the caused exception as a response. In Camel 1.5 you can now change this behavior with the new handle DSL. The handle is a Predicate that is overloaded to accept three types of parameters:
- Boolean
- Predicate
- Expression that will be evaluates as a Predicate using this rule set: If the expressions returns a Boolean its used directly. For any other response its regarded as
true
if the response isnot null
.
For instance to mark all ValidationException
as being handled we can do this:
...
You can define exception clauses either as:
- global
- or route specific
We start off with the sample sample that we change over time. First off we use only global exception clauses:
...