You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by Daniel Pocock <da...@pocock.pro> on 2014/12/12 10:26:24 UTC

onException documentation

In the wiki, it very briefly mentions that onException supports nested
exceptions:

http://camel.apache.org/exception-clause.html

"Camel will start from the bottom (nested caused by) and recursive up in
the exception hierarchy to find the first matching |onException| clause"

In the code, CatchProcessor.catches() uses
           for (final Throwable e :
ObjectHelper.createExceptionIterable(exception)) {

The ObjectHelper javadoc says
    Creates an Iterable to walk the exception from the bottom up
    (the last caused by going upwards to the root exception).

Looking at the createExceptionIterable code, it appears that the root
exception is the first returned by the iterator.  The stuff in the
comment in parentheses is not clear: when I see the word "last", it
gives me the impression that it is talking about the last in time order
and that is the opposite of what the method does.  In this context, I
think it is intended that the word "last" means the bottom or last
exception in a printed stack trace.

This feature is quite useful and it is something that could be clearer
in the wiki, rather than being buried half way down, it would be nice to
make the point at the top that onException can recognize any exception
in a chain and not just the exception wrapping all the others.  E.g. the
SMPP component often wraps the NegativeResponseException from jSMPP in
SmppException but it is much more useful to use onException with a
NegativeResponseException to extract the SMPP error code.

I don't mind updating this documentation myself but I thought it would
be useful to confirm that this is how people intend it to be used.

Regards,

Daniel