sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache Sling > Effective Exceptions
Date Mon, 07 Feb 2011 10:10:00 GMT
    <base href="">
            <link rel="stylesheet" href="/confluence/s/2036/9/1/_/styles/combined.css?spaceKey=SLING&amp;forWysiwyg=true"
<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="">Effective
    <h4>Page <b>edited</b> by             <a href="">Felix
                         <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>
    </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=""
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>

	<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
	<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>

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

	<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>

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

	<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>

<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=""
class="external-link" rel="nofollow"></a></p>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href=""
class="grey">Change Notification Preferences</a>
        <a href="">View
        <a href="">View
        <a href=";showCommentArea=true#addcomment">Add

View raw message