Passing through exceptions has the following advantages IMHO: - The client can decide how to expose that error (whether just logging is fine or something more obvious). This cannot be achieved by just setting up a utility method, because that one does only see the null return value and not the original reason for that. - Tracing problems during development is much easier (instead of looking at the log I can see the full exception) - It allows to use it for something like validation in Sling Models - It is less error-prone to the developers (you can easily forget to either use the utility method or check for null) - In my regard in most of the cases if adaptation fails, there is something wrong with the deployment (required bundles are not installed, components are not running, ….) and I cannot reasonably work around that issue in the code -> that calls for an exception
Regards, Konrad On 02 Jul 2014, at 12:33, Alexander Klimetschek <aklim...@adobe.com> wrote: > Just reading up on this and have the basic question: what is the motivation > for passing through the exceptions? > > From what I can see it is simply that the exceptions become visible to the > developer, which can be done by properly logging them (in the > adapterfactories etc.). It was mentioned that this decision (whether to log > or not) depends on the application = user of the adaptTo call. But I haven't > seen an example of that and are unsure that really is the case. > > The example Stefan gave [1] is just about removing the boilerplate of the > null check + throwing a runtime exception, which could be handled using a > static utility method (adaptOrThrow, but outside the adaptable interface). > Also, this seems to be heavily depending on the style of the application > code, whether exceptions are used a lot or null handling (using optionals > etc.) is prefered and done consistently. Hence I am not sure if that requires > a major change in the adaptable interface contract. > > [1] > https://issues.apache.org/jira/browse/SLING-3714?focusedCommentId=14048040&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14048040 > > Cheers, > Alex