001: /*
002: * $Revision: 1.1 $
003: * $Date: 2006/06/10 13:32:32 $
004: * $Author: fdietz $
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: */
020: /*--
021:
022: $Id: SpellException.java,v 1.1 2006/06/10 13:32:32 fdietz Exp $
023:
024: Copyright (C) 2000 Brett McLaughlin & Jason Hunter.
025: All rights reserved.
026:
027: */
028: package org.columba.mail.spellcheck.cswilly;
029:
030: import java.io.PrintStream;
031: import java.io.PrintWriter;
032:
033: /**
034: * <b><code>SpellException</code></b>
035: * <p>
036: * This <code>Exception</code> subclass is the top level
037: * <code>Exception</code> that spell classes
038: * can throw. It's subclasses add specificity to the
039: * problems that can occur using spell, but this single
040: * <code>Exception</code> can be caught to handle all
041: * spell specific problems.
042: * <p>
043: * <b>This is a copy and paste of the JDOMException, create due.</b>
044: * @author Brett McLaughlin
045: * @author Jason Hunter
046: * @version 1.0
047: */
048: public class SpellException extends Exception {
049: /** A wrapped <code>Throwable</code> */
050: protected Throwable rootCause;
051:
052: /**
053: * <p>
054: * This will create an <code>Exception</code>.
055: * </p>
056: */
057: public SpellException() {
058: super ("Error occurred in spell application.");
059: }
060:
061: /**
062: * <p>
063: * This will create an <code>Exception</code> with the given message.
064: * </p>
065: *
066: * @param message <code>String</code> message indicating
067: * the problem that occurred.
068: */
069: public SpellException(String message) {
070: super (message);
071: }
072:
073: /**
074: * <p>
075: * This will create an <code>Exception</code> with the given message
076: * and wrap another <code>Exception</code>. This is useful when
077: * the originating <code>Exception</code> should be held on to.
078: * </p>
079: *
080: * @param message <code>String</code> message indicating
081: * the problem that occurred.
082: * @param exception <code>Exception</code> that caused this
083: * to be thrown.
084: */
085: public SpellException(String message, Throwable rootCause) {
086: super (message);
087: this .rootCause = rootCause;
088: }
089:
090: /**
091: * <p>
092: * This returns the message for the <code>Exception</code>. If
093: * there is a root cause, the message associated with the root
094: * <code>Exception</code> is appended.
095: * </p>
096: *
097: * @return <code>String</code> - message for <code>Exception</code>.
098: */
099: public String getMessage() {
100: if (rootCause != null) {
101: return super .getMessage() + ": " + rootCause.getMessage();
102: } else {
103: return super .getMessage();
104: }
105: }
106:
107: /**
108: * <p>
109: * This prints the stack trace of the <code>Exception</code>. If
110: * there is a root cause, the stack trace of the root
111: * <code>Exception</code> is printed right after.
112: * </p>
113: */
114: public void printStackTrace() {
115: super .printStackTrace();
116:
117: if (rootCause != null) {
118: System.err.print("Root cause: ");
119: rootCause.printStackTrace();
120: }
121: }
122:
123: /**
124: * <p>
125: * This prints the stack trace of the <code>Exception</code> to the given
126: * PrintStream. If there is a root cause, the stack trace of the root
127: * <code>Exception</code> is printed right after.
128: * </p>
129: */
130: public void printStackTrace(PrintStream s) {
131: super .printStackTrace(s);
132:
133: if (rootCause != null) {
134: s.print("Root cause: ");
135: rootCause.printStackTrace(s);
136: }
137: }
138:
139: /**
140: * <p>
141: * This prints the stack trace of the <code>Exception</code> to the given
142: * PrintWriter. If there is a root cause, the stack trace of the root
143: * <code>Exception</code> is printed right after.
144: * </p>
145: */
146: public void printStackTrace(PrintWriter w) {
147: super .printStackTrace(w);
148:
149: if (rootCause != null) {
150: w.print("Root cause: ");
151: rootCause.printStackTrace(w);
152: }
153: }
154:
155: /**
156: * <p>
157: * This will return the root cause <code>Throwable</code>, or null
158: * if one does not exist.
159: * </p>
160: *
161: * @return <code>Throwable</code> - the wrapped <code>Throwable</code>.
162: */
163: public Throwable getRootCause() {
164: return rootCause;
165: }
166: }
|