[Jspro-cvs] jsPro/error Error.js,NONE,1.1
Brought to you by:
wigleys
From: Stuart W. <wi...@us...> - 2005-02-22 11:23:29
|
Update of /cvsroot/jspro/jsPro/error In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28755/error Added Files: Error.js Log Message: no message --- NEW FILE: Error.js --- /** * +--------------------------------------------------------------------------+ * | jsPro - Error | * +--------------------------------------------------------------------------+ * | Copyright (C) 2001-2005 Stuart Wigley | * +--------------------------------------------------------------------------+ * | This library is free software; you can redistribute it and/or modify it | * | under the terms of the GNU Lesser General Public License as published by | * | the Free Software Foundation; either version 2.1 of the License, or (at | * | your option) any later version. | * | | * | This library is distributed in the hope that it will be useful, but | * | WITHOUT ANY WARRANTY; without even the implied warranty of | * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | * | General Public License for more details. | * | | * | You should have received a copy of the GNU Lesser General Public License | * | along with this library; if not, write to the Free Software Foundation, | * | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | * +--------------------------------------------------------------------------+ * | Authors: Stuart Wigley <stu...@ya...> | * | Randolph Fielding <gat...@ci...> | * +--------------------------------------------------------------------------+ * $Id: Error.js,v 1.1 2005/02/22 11:23:16 wigleys Exp $ */ /** * Property used in <code>Error.handleError</code> to specify how errors are * reported. Permissable values are: * * 0 No errors are reported. * 1 Report the error name and error message using the status bar of the * active browser window. * 2 Report the error name and error message using an alert box. * 3 Report the error name, error message and debug message using an alert * box. * 4 Report the error name, error message and debug message using a debug * window. An instance of the Debug() class must be available. */ function Error(oDebugWindow, iDebugLevel) { this.oDebugWindow = oDebugWindow; this.iDebugLevel = 4; } /** * * @author Stuart Wigley * @author Randolph Fielding * @requires <code>Debug.print(vMixedValue, sMessageType)</code> * @see <code>Debug()</code> * @see <code>Debug.print()</code> */ Error.prototype.handleError = function() { var sDebugMessage = this.debug; var sErrorMessage = (sDebugMessage) ? sDebugMessage : ''; switch (this.iDebugLevel) { case 0 : break; case 1 : window.status = this.name + ': ' + this.message; break; case 2 : window.alert(this.name + '\n\n' + this.message); break; case 3 : window.alert(this.name + '\n\n' + this.message + '\n\n' + sErrorMessage); break; case 4 : var jsProDebugWindow = oDebug; if (jsProDebugWindow) { var oDebugWindow = jsProDebugWindow.debugWindow; if (oDebugWindow && !oDebugWindow.closed) { jsProDebugWindow.print(this.name + ' ' + this.message + ' ' + sErrorMessage, 1); } } } } /** * Creates an object that is a subclass of Error for handling * ArrayIndexOutOfBounds exceptions. * * @author Stuart Wigley * @author Randolph Fielding * @param sMethodName the name of the method where the exception was thrown * @param iIndex the index of a hypothetical array member attempting to * be accessed * @param iArrayLength the length of the array */ function ArrayIndexOutOfBoundsException(sMethodName, iIndex, iArrayLength) { this.name = 'ArrayIndexOutOfBoundsException'; this.message = sMethodName + ' has been accessed with an illegal index that is either negative or greater than the size of the array.'; this.debug = 'Attempting to access index ' + iIndex.toString() + ', but array has an index range of 0 to ' + (iArrayLength - 1).toString() + '.'; } ArrayIndexOutOfBoundsException.prototype = new Error(); /** * Creates an object that is a subclass of Error for handling IllegalArgument * exceptions. * * @author Stuart Wigley * @author Randolph Fielding * @param sMethodName the name of the method where the exception was thrown * @param vExpectedArgs the number of arguments expected * @param iActualArgs the number of arguments received */ function IllegalArgumentException(sMethodName, vExpectedArgs, iActualArgs) { this.name = 'IllegalArgumentException'; this.message = sMethodName + ' has been passed an illegal number of arguments.'; this.debug = 'Expected ' + vExpectedArgs.toString() + ' argument(s), but received ' + iActualArgs.toString() + ' argument(s).'; } IllegalArgumentException.prototype = new Error(); /** * Creates an object that is a subclass of Error for handling IllegalValue * exceptions. * * @author Randolph Fielding * @param sMethodName the name of the method where the exception was thrown * @param sVariableName the name of the variable containing the illegal value * @param vExpectedVal the value expected in the variable containing the * illegal value * @param vActualVal the value currently in the variable containing the * illegal value */ function IllegalValueException(sMethodName, sVariableName, vExpectedVal, vActualVal) { this.name = 'IllegalValueException'; this.message = sMethodName + ' has encountered an illegal value in variable ' + sVariableName + '.' this.debug = 'Expected a value of ' + vExpectedVal.toString() + ', but contains a value of ' + vActualVal.toString() + '.' } IllegalValueException.prototype = new Error(); /** * Creates an object that is a subclass of Error for handling * MethodNotAvailable exceptions. * * @author Stuart Wigley * @author Randolph Fielding * @param sMethodName the name of the method where the exception was thrown * @param sMethodNameNA the name of the method that was not available */ function MethodNotAvailableException(sMethodName, sMethodNameNA) { this.name = 'MethodNotAvailableException'; this.message = 'A method has been called that is not available.'; this.debug = sMethodName + ' attempted to call ' + sMethodNameNA + '.'; } MethodNotAvailableException.prototype = new Error(); /** * Creates an object that is a subclass of Error for handling * PropertyNotAvailable exceptions. * * @author Randolph Fielding * @param sMethodName the name of the method where the exception was thrown * @param sPropNameNA the name of the property that was not available */ function PropertyNotAvailableException(sMethodName, sPropNameNA) { this.name = 'PropertyNotAvailableException'; this.message = 'A property has been accessed that is not available.'; this.debug = sMethodName + ' attempted to access ' + sPropNameNA + '.'; } PropertyNotAvailableException.prototype = new Error(); /** * Creates an object that is a subclass of Error for handling TypeMismatch * exceptions. * * @author Stuart Wigley * @author Randolph Fielding * @param sMethodName the name of the method where the exception was thrown * @param sExpectedType the name of the expected type of an argument * @param sActualType the name of the actual type of an argument */ function TypeMismatchException(sMethodName, sExpectedType, sActualType) { this.name = 'TypeMismatchException'; this.message = sMethodName + ' has been passed an argument with an illegal or inappropriate type.'; this.debug = 'Expected an argument with a type of ' + sExpectedType + ', but received an argument with a type of ' + sActualType + '.'; } TypeMismatchException.prototype = new Error(); /** * Creates an object that is a subclass of Error for handling Unknown * exceptions. * * @author Stuart Wigley * @author Randolph Fielding * @interface <code>new UnknownException(sMethodName)</code> * @param sMethodName the name of the method where the exception was thrown */ function UnknownException(sMethodName) { this.name = 'UnknownException'; this.message = 'An unknown error has occurred in ' + sMethodName + '.'; } UnknownException.prototype = new Error(); |