...
Camel uses DefaultExceptionPolicyStrategy
to determine a strategy how an exception being thrown should be handled by which onException
clause. This The strategy is:
- the order in which the
onException
is configured takes precedence. Camel will test from first...last defined. - camel 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 test 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:
Code Block | ||||
---|---|---|---|---|
| ||||
onException(FileNotFoundExceptionIOException.class).handledmaximumRedeliveries(true).to("log:nofile")3); onException(OrderFailedException.class).maximumRedeliveries(2); onException(IOException.class).maximumRedeliveries(3); |
In the sample above we have defined two exceptions in which FileNotFoundException IOException is first, so Camel will pickup this exception if there is a match. IOException that is more general is selected then.
...
Then Camel will try testing the exception in this order: FileNotFoundException, IOException, OrderFailedException and RuntimeCamelException.
As we have defined a onException(FileNotFoundException) Camel will have a match very early.select this as it's an exact match.
If we add a third onException clause with the FileNotFoundException
Code Block | ||||
---|---|---|---|---|
| ||||
onException(IOException.class).maximumRedeliveries(3);
onException(OrderFailedException.class).maximumRedeliveries(2);
onException(FileNotFoundException.class).handled(true).to("log:nofile");
|
Then with the previous example Camel will now use the last onException(FileNotFoundException.class)
as its an exact match. Since this is an exact match it will overrule the general IOException that was used before to handle the same exception thrown.
Now a new situation However if this exception was thrown instead:
...
Then the onException(OrderFailedException.class)
will be selected - no surprise here.
And this last sample demonstrates the instanceof
test aspect in which Camel will select an exception if it's an instance of the defined exception in the onException
clause. Illustrated as:
...