001: package net.firstpartners.nounit.utility;
002:
003: /**
004: * Title: NoUnit - Identify Classes that are not being unit Tested
005: *
006: * Copyright (C) 2001 Paul Browne , FirstPartners.net
007: *
008: *
009: * This program is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; either version 2
012: * of the License, or (at your option) any later version.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
017: * GNU General Public License for more details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with this program; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * @author Paul Browne
024: * @version 0.7
025: */
026:
027: /**
028: * System Wide Exception (containing original Exception & user friendly message)
029: * thrown whenever invalid values are found.
030: */
031: public class NoUnitException extends Exception {
032:
033: //User Friendly Error Message , initialised to empty string
034: private String userErrorMessage;
035: private Exception internalException;
036:
037: /**
038: * Constructor , repackages other Exceptions to add (User Friendly) information
039: * @param inException to hold
040: * @param userFriendlyMessage to display to user
041: */
042: public NoUnitException(Exception inException,
043: String userFriendlyMessage) {
044:
045: //Call the super constructor
046: super (inException.toString());
047:
048: //Set the Internal Error
049: internalException = inException;
050:
051: //Set the user Friendly Error Message
052: userErrorMessage = userFriendlyMessage;
053:
054: }
055:
056: /**
057: * Constructor , calls exception with value pair information
058: * @param inValidValueName - the name the value was stored under
059: * @param inValidValue - the value that was rejected
060: */
061: public NoUnitException(String inValidValueName, String inValidValue) {
062: super ("Invalid value submitted (" + inValidValue
063: + ") under keyname " + inValidValueName);
064:
065: //Set the internal error message
066: userErrorMessage = this .toString();
067:
068: //Set the InternalException
069: internalException = this ;
070:
071: }
072:
073: /**
074: * Constructor , calls exception with value pair information , plus reason
075: * @param inValidValueName - the name the value was stored under
076: * @param inValidValue - the value that was rejected
077: * @param reason - the reason why the value was rejected
078: */
079: public NoUnitException(String inValidValueName,
080: String inValidValue, String reason) {
081: super ("Invalid value submitted (" + inValidValue
082: + ") under keyname " + inValidValueName + " reason: "
083: + reason);
084:
085: //Set the InternalException
086: internalException = this ;
087:
088: //Set the internal error message
089: userErrorMessage = this .toString();
090: }
091:
092: /**
093: * Constructor , calls exception with value pair information , plus reason
094: * @param inUserErrorMessage that will be displayed to the user
095: */
096: public NoUnitException(String inUserErrorMessage) {
097: super (inUserErrorMessage);
098:
099: //Set the InternalException
100: internalException = this ;
101:
102: //Set the internal error message
103: userErrorMessage = inUserErrorMessage;
104: }
105:
106: /**
107: * Returns the userFriendly Error Message
108: * @return userErrorMessage
109: */
110: public String getUserErrorMessage() {
111: return userErrorMessage;
112: }
113:
114: /**
115: * Over-rides the toString method to provide more information.
116: * @return infoString containing concatanated original error (if any) , plus
117: * any user friendly messages.
118: */
119: public String toString() {
120:
121: //Give as much information as possible about this exception in string format
122: StringBuffer infoString = new StringBuffer("Exception:");
123: infoString.append(super .toString());
124: infoString.append("\n");
125: infoString.append("UserMessage:");
126: infoString.append(getUserErrorMessage());
127: infoString.append("\n");
128:
129: //Give Info if internal exception has anything useful...
130: if ((internalException != null)
131: && (!(internalException instanceof NoUnitException))) {
132: infoString.append("Original Exception:");
133: infoString.append(internalException.toString());
134: infoString.append("\n");
135: }
136:
137: return infoString.toString();
138:
139: }
140:
141: /**
142: * return the internal / original Exception , if any
143: * @return internalException that is stored when this was created
144: */
145: public Exception getOriginalException() {
146:
147: return this.internalException;
148:
149: }
150:
151: }
|