sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Sling > Effective Exceptions
Date Mon, 07 Feb 2011 10:10:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2036/9/1/_/styles/combined.css?spaceKey=SLING&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/SLING/Effective+Exceptions">Effective
Exceptions</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~fmeschbe">Felix
Meschberger</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-unchanged" >h1. Rethinking the SlingException
<br> <br></td></tr>
            <tr><td class="diff-changed-lines" >{excerpt:hidden=true}We should
define the {{SlingException}} as a {{RuntimeException}} and use it as the base class for all
exceptions defined in the Sling <span class="diff-changed-words">API.<span class="diff-added-chars"style="background-color:
#dfd;"> (IMPLEMENTED)</span>{excerpt}</span> <br></td></tr>
            <tr><td class="diff-unchanged" > <br>Status: IMPLEMENTED <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h1><a name="EffectiveExceptions-RethinkingtheSlingException"></a>Rethinking
the SlingException</h1>



<p>Status: IMPLEMENTED<br/>
Created: 23. December 2007<br/>
Author: fmeschbe</p>



<p>Inspired by Barry Ruzek's article <a href="http://dev2dev.bea.com/pub/a/2006/11/effective-exceptions.html"
class="external-link" rel="nofollow">Effective Java Exceptions</a>, I went out to
revisit the exceptions we have defined in the Sling API. This is what I came out with:</p>

<ul>
	<li>We have 4 Exceptions, all of which are checked exceptions</li>
	<li>The <tt>SlingException</tt> is a base exception and is declared almost
everywhere</li>
	<li>The <tt>HttpStatusCodeException</tt> is an <tt>IOException</tt>
not a <tt>SlingException</tt> and is not declared to be thrown anywhere</li>
	<li>We have two documented possibilities of throwing a runtime exception: The <tt>AccessControlException</tt>
possibly thrown when accessing a resource through the <tt>ResourceResolver</tt>.</li>
</ul>


<p>Thinking about these (checked) Exceptions, I propose to change the Sling API as follows:</p>

<ol>
	<li>The <tt>SlingException</tt> is a <tt>RuntimeException</tt>
and is used as the base exception for all exceptions defined by the Sling API.</li>
	<li>The <tt>HttpStatusCodeException</tt> is removed. Status codes are better
reported back to the client using <tt>HttpServletResponse.sendError()</tt>.</li>
	<li>Add <tt>ResourceNotFoundException</tt> which may be used by scripts
and servlets to report a missing resource.</li>
	<li>Add <tt>QuerySyntaxException</tt> thrown from the <tt>ReourceResolver.findResources</tt>
and <tt>ResourceResolver.queryResources</tt> methods.</li>
	<li>Add <tt>ScriptEvaluationException</tt> thrown by <tt>SlingScript.eval</tt>
wrapping and further failure cause.</li>
	<li>Drop <tt>ServiceNotAvailableException</tt> and the respective <tt>ServiceLocator.getRequiredService</tt>:
The method and thus the exception are probably not very usefull. Rather the <tt>ServiceLocator.getService</tt>
method should be used and the result checked for <tt>null</tt>.</li>
	<li>Add <tt>SlingIOException</tt> and <tt>SlingServletException</tt>
both extending <tt>SlingException</tt>. These exceptions are used to wrap <tt>IOException</tt>
and <tt>ServletException</tt> instances to be able to forward them as runtime
exceptions to the appropriate error handling.</li>
</ol>


<p>This change also has an influence on the implementation of the Sling API:</p>

<ol>
	<li>The main point is the handling of the <tt>SlingException</tt> in the
Sling main servlet.</li>
	<li>Other locations catching <tt>Exception</tt> should be revisited to
make sure no <tt>SlingException</tt> is swallowed and not treated correctly.</li>
</ol>


<p>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.</p>

<p>The proposed API changes can be evaluated in the Sling whiteboard at <a href="http://svn.apache.org/repos/asf/incubator/sling/whiteboard/fmeschbe/effective_exceptions"
class="external-link" rel="nofollow">http://svn.apache.org/repos/asf/incubator/sling/whiteboard/fmeschbe/effective_exceptions</a></p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/SLING/Effective+Exceptions">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=73229&revisedVersion=9&originalVersion=8">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/SLING/Effective+Exceptions?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message