From: Antony C. <an...@sm...> - 2005-06-22 10:45:41
|
Matthew, you are a true code digger! Good idea, user exceptions should contain user-friendly message and could be used to report back to user (could still be logged at a finer level). Can't see that "You don't have access rights allowing you to delete sections here." is output to user in LogBookFacility!? Antony ps. after your Skye visit, can we now refer to you as (Matthew) The Bucket! On 21 Jun 2005, at 17:05, Matthew Buckett wrote: > At the moment whenever an exception gets thrown from a method in > BuildingSession (or subclass) the calling code (normally a facility) > logs the exception. > > The problem is that some of these errors are just users doing silly > things and don't need to be logged. One example of this is when a user > tries to remove a section from a logbook that contains questions a > BuildingServerException is thrown from the > LogBookSessionImpl.deleteSection() method. > > Now the LogBookSession.deleteSection() method may throw a > BuildingServerException for a much more serious error as well (not > being able to fing the logbook associated with the session). > > To allow us to still log the serious errors but ignore (but still > display to the user) the others I create a new exception > BuildingServerUserException that subclasses BuildingServerException > and then a special catch clause can be added in places where it is > needed. > > As an example attached is the patch that shows the changes to > LogBookSessionImpl. > > Comments? > > -- > +--Matthew Buckett-----------------------------------------+ > | VLE Developer, Learning Technologies Group | > | Tel: +44 (0) 1865 283660 http://www.oucs.ox.ac.uk/ | > +------------Computing Services, University of Oxford------+ > Index: src/org/bodington/logbook/server/LogBookSessionImpl.java > =================================================================== > RCS file: > /usr/cvs/src/master/bodington/src/org/bodington/logbook/server/ > LogBookSessionImpl.java,v > retrieving revision 1.6 > diff -u -r1.6 LogBookSessionImpl.java > --- src/org/bodington/logbook/server/LogBookSessionImpl.java 27 May > 2005 14:40:12 -0000 1.6 > +++ src/org/bodington/logbook/server/LogBookSessionImpl.java 21 Jun > 2005 15:55:31 -0000 > @@ -462,14 +462,17 @@ > * Deletes a specific section. > * > * @exception java.rmi.RemoteException > - * @exception BuildingServerException > + * @exception BuildingServerException Something went seriously wrong. > + * @exception BuildingServerUserException Something went wrong that > should > + * be reported to the user but probably doesn't need to be logged. > + * > */ > public void deleteSection( PrimaryKey section_id ) > throws RemoteException, BuildingServerException > { > LogBook lb = getLogBook(); > if ( !lb.checkPermission( Permission.EDIT ) ) > - throw new BuildingServerException( "You don't have access rights > allowing you to delete sections here." ); > + throw new BuildingServerUserException( "You don't have access > rights allowing you to delete sections here." ); > > invalidateCsvQuestionFile(); > > @@ -479,7 +482,7 @@ > LogBookQuestion[] questions = this.getQuestionsInOrder( > section.getLogBookSectionId() ); > > if ( questions!=null && questions.length>0 ) > - throw new BuildingServerException( "Can't delete sections that > contain questions." ); > + throw new BuildingServerUserException( "Can't delete sections that > contain questions." ); > > // delete it > section.delete(); > Index: src/org/bodington/logbook/servlet/LogBookFacility.java > =================================================================== > RCS file: > /usr/cvs/src/master/bodington/src/org/bodington/logbook/servlet/ > LogBookFacility.java,v > retrieving revision 1.7 > diff -u -r1.7 LogBookFacility.java > --- src/org/bodington/logbook/servlet/LogBookFacility.java 27 May 2005 > 14:40:12 -0000 1.7 > +++ src/org/bodington/logbook/servlet/LogBookFacility.java 21 Jun 2005 > 15:55:31 -0000 > @@ -66,6 +66,7 @@ > import org.bodington.logbook.server.*; > import org.bodington.database.PrimaryKey; > import org.bodington.server.BuildingContext; > +import org.bodington.server.BuildingServerUserException; > import org.bodington.server.BuildingSession; > import org.bodington.server.BuildingSessionManagerImpl; > import org.bodington.server.BuildingServerException; > @@ -1554,6 +1555,11 @@ > { > lb_session.deleteSection( section_id ); > } > + catch (BuildingServerUserException bsue) > + { > + out.write(bsue.getMessage()); > + return; > + } > catch ( BuildingServerException bsex ) > { > logException( out, "LogBookFacility", "deleteSection", > /* > ====================================================================== > The Bodington System Software License, Version 1.0 > > Copyright (c) 2001 The University of Leeds. All rights reserved. > > Redistribution and use in source and binary forms, with or without > modification, are permitted provided that the following conditions are > met: > > 1. Redistributions of source code must retain the above copyright > notice, > this list of conditions and the following disclaimer. > > 2. Redistributions in binary form must reproduce the above copyright > notice, this list of conditions and the following disclaimer in the > documentation and/or other materials provided with the distribution. > > 3. The end-user documentation included with the redistribution, if > any, > must include the following acknowledgement: "This product includes > software developed by the University of Leeds > (http://www.bodington.org/)." Alternately, this acknowledgement may > appear in the software itself, if and wherever such third-party > acknowledgements normally appear. > > 4. The names "Bodington", "Nathan Bodington", "Bodington System", > "Bodington Open Source Project", and "The University of Leeds" must > not be > used to endorse or promote products derived from this software without > prior written permission. For written permission, please contact > d.g...@le.... > > 5. The name "Bodington" may not appear in the name of products derived > from this software without prior written permission of the University > of > Leeds. > > THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED > WARRANTIES, INCLUDING, BUT NOT LIMITED TO, TITLE, THE IMPLIED > WARRANTIES > OF QUALITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO > EVENT SHALL THE UNIVERSITY OF LEEDS OR ITS CONTRIBUTORS BE LIABLE FOR > ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE > GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS > INTERRUPTION) > HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, > STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING > IN > ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE > POSSIBILITY OF SUCH DAMAGE. > ========================================================= > > This software was originally created by the University of Leeds and > may contain voluntary > contributions from others. For more information on the Bodington Open > Source Project, please > see http://bodington.org/ > > ====================================================================== > */ > > package org.bodington.server; > > import org.bodington.pool.ObjectPoolException; > > /** > * Class that should be thrown when an error is encountered that > should be show > * to the user but probably doesn't need to be logged. > * @author buckett > */ > public class BuildingServerUserException extends > BuildingServerException > { > > /** > * Create a new BuildingServerUserException. > * @param s The error message that will probably be show to the > user. > */ > public BuildingServerUserException(String s) > { > super(s); > } > > > } |