DUE TO SPAM, SIGN-UP IS DISABLED. Goto Selfserve wiki signup and request an account.
Rethinking the SlingException
| Excerpt | ||
|---|---|---|
| ||
We should define the |
Status: IMPLEMENTED
Created: 23. December 2007
Author: fmeschbe
| Table of Contents | ||
|---|---|---|
|
Inspired by Barry Ruzek's article Effective Java Exceptions, I went out to revisit the exceptions we have defined in the Sling API. This is what I came out with:
- We have 4 Exceptions, all of which are checked exceptions
- The
SlingExceptionis a base exception and is declared almost everywhere - The
HttpStatusCodeExceptionis anIOExceptionnot aSlingExceptionand is not declared to be thrown anywhere - We have two documented possibilities of throwing a runtime exception: The
AccessControlExceptionpossibly thrown when accessing a resource through theResourceResolver.
Thinking about these (checked) Exceptions, I propose to change the Sling API as follows:
- The
SlingExceptionis aRuntimeExceptionand is used as the base exception for all exceptions defined by the Sling API. - The
HttpStatusCodeExceptionis removed. Status codes are better reported back to the client usingHttpServletResponse.sendError(). - Add
ResourceNotFoundExceptionwhich may be used by scripts and servlets to report a missing resource. - Add
QuerySyntaxExceptionthrown from theReourceResolver.findResourcesandResourceResolver.queryResourcesmethods. - Add
ScriptEvaluationExceptionthrown bySlingScript.evalwrapping and further failure cause. - Drop
ServiceNotAvailableExceptionand the respectiveServiceLocator.getRequiredService: The method and thus the exception are probably not very usefull. Rather theServiceLocator.getServicemethod should be used and the result checked fornull. - Add
SlingIOExceptionandSlingServletExceptionboth extendingSlingException. These exceptions are used to wrapIOExceptionandServletExceptioninstances to be able to forward them as runtime exceptions to the appropriate error handling.
This change also has an influence on the implementation of the Sling API:
- The main point is the handling of the
SlingExceptionin the Sling main servlet. - Other locations catching
Exceptionshould be revisited to make sure noSlingExceptionis swallowed and not treated correctly.
Another point with the Sling main servlet is, that it is important to not call error handling servlets from included requests but only from the topmost request.
The proposed API changes can be evaluated in the Sling whiteboard at http://svn.apache.org/repos/asf/incubator/sling/whiteboard/fmeschbe/effective_exceptions