Hi Eric
....I stumbled over some areas in the code where I noticed that an original exception is caught, logged AND rethrown wrapped inside a SynapseException or SynapseUtilException (specific RuntimeExceptions). The original exception is then mostly logged as an error, no matter whether the caller may consider the exception to be critical or easily recoverable. If he is able to recover, the original problem is already logged as an error and he may only add a warning about the way he could recover.
The good thing is that the almost the whole code looks pretty consistent in this regard and I bet this is due to the following comment
"We always log each exception the first time it is caught, and throw a SynapseException with an appropriate error message that tries to give out additional information on why the exception occurred."
in the developer guidelines at
http://cwiki.apache.org/synapse/developer-guidelines.html (Would it make sense
to make this guideline easier available? Integrate or link it from the main
page?).
What is the reasoning of this exception handling/logging approach?
So far I was used to the following rule(s):
Either throw (chaining/wrapping of original exception) or log, except on
component boundaries where original exceptions have to be logged AND new
exceptions created and thrown (no chaining/wrapping of original exception for
this case, as implementation details and concrete stack/dependencies shall be
hidden from the caller). So far I never had problems with this approach. What
are other's experiences?
Of course I will follow the chosen approach - this is more out of personal
interest.
This basically follows some ideas from Joshua Bloch (Effective Java:
Programming Language Guide), and some discussions on the use of checked
exceptions vs runtime exceptions.
Item 40:Use checked exceptions for recoverable conditions and run-time
exceptions for programming errors
Item 41:Avoid unnecessary use of checked exceptions
Item 43: Throw exceptions appropriate to the abstraction
I personally follow logging of an Exception the first time you find out
about it (i.e. thrown from an external system to you), or you throwing
an exception - so that most of the context information about the
exception could be logged for analysis. Most of the cases where a
SynapseException is thrown are unrecoverable situations - since many are
dependent on a myriad of causes stemming from AxisFaults.. There are
places in the code where we catch these, and handle error recovery etc,
where appropriate. If we know we can recover from some some types of
errors (e.g. transport reconnects etc) we do that too..
cheers
asankha
[1] http://www.ibm.com/developerworks/java/library/j-jtp05254.html
[2]
http://java.sun.com/docs/books/tutorial/essential/exceptions/runtime.html
--
Asankha C. Perera
AdroitLogic, http://adroitlogic.org
http://esbmagic.blogspot.com
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@synapse.apache.org
For additional commands, e-mail: dev-h...@synapse.apache.org