KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > spellcheck > cswilly > SpellException


1 /*
2  * $Revision: 1.1 $
3  * $Date: 2006/06/10 13:32:32 $
4  * $Author: fdietz $
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */

20 /*--
21
22 $Id: SpellException.java,v 1.1 2006/06/10 13:32:32 fdietz Exp $
23
24 Copyright (C) 2000 Brett McLaughlin & Jason Hunter.
25 All rights reserved.
26
27 */

28 package org.columba.mail.spellcheck.cswilly;
29
30 import java.io.PrintStream JavaDoc;
31 import java.io.PrintWriter JavaDoc;
32
33
34 /**
35  * <b><code>SpellException</code></b>
36  * <p>
37  * This <code>Exception</code> subclass is the top level
38  * <code>Exception</code> that spell classes
39  * can throw. It's subclasses add specificity to the
40  * problems that can occur using spell, but this single
41  * <code>Exception</code> can be caught to handle all
42  * spell specific problems.
43  * <p>
44  * <b>This is a copy and paste of the JDOMException, create due.</b>
45  * @author Brett McLaughlin
46  * @author Jason Hunter
47  * @version 1.0
48  */

49 public class SpellException extends Exception JavaDoc {
50     /** A wrapped <code>Throwable</code> */
51     protected Throwable JavaDoc rootCause;
52
53     /**
54  * <p>
55  * This will create an <code>Exception</code>.
56  * </p>
57  */

58     public SpellException() {
59         super("Error occurred in spell application.");
60     }
61
62     /**
63  * <p>
64  * This will create an <code>Exception</code> with the given message.
65  * </p>
66  *
67  * @param message <code>String</code> message indicating
68  * the problem that occurred.
69  */

70     public SpellException(String JavaDoc message) {
71         super(message);
72     }
73
74     /**
75  * <p>
76  * This will create an <code>Exception</code> with the given message
77  * and wrap another <code>Exception</code>. This is useful when
78  * the originating <code>Exception</code> should be held on to.
79  * </p>
80  *
81  * @param message <code>String</code> message indicating
82  * the problem that occurred.
83  * @param exception <code>Exception</code> that caused this
84  * to be thrown.
85  */

86     public SpellException(String JavaDoc message, Throwable JavaDoc rootCause) {
87         super(message);
88         this.rootCause = rootCause;
89     }
90
91     /**
92  * <p>
93  * This returns the message for the <code>Exception</code>. If
94  * there is a root cause, the message associated with the root
95  * <code>Exception</code> is appended.
96  * </p>
97  *
98  * @return <code>String</code> - message for <code>Exception</code>.
99  */

100     public String JavaDoc getMessage() {
101         if (rootCause != null) {
102             return super.getMessage() + ": " + rootCause.getMessage();
103         } else {
104             return super.getMessage();
105         }
106     }
107
108     /**
109  * <p>
110  * This prints the stack trace of the <code>Exception</code>. If
111  * there is a root cause, the stack trace of the root
112  * <code>Exception</code> is printed right after.
113  * </p>
114  */

115     public void printStackTrace() {
116         super.printStackTrace();
117
118         if (rootCause != null) {
119             System.err.print("Root cause: ");
120             rootCause.printStackTrace();
121         }
122     }
123
124     /**
125  * <p>
126  * This prints the stack trace of the <code>Exception</code> to the given
127  * PrintStream. If there is a root cause, the stack trace of the root
128  * <code>Exception</code> is printed right after.
129  * </p>
130  */

131     public void printStackTrace(PrintStream JavaDoc s) {
132         super.printStackTrace(s);
133
134         if (rootCause != null) {
135             s.print("Root cause: ");
136             rootCause.printStackTrace(s);
137         }
138     }
139
140     /**
141  * <p>
142  * This prints the stack trace of the <code>Exception</code> to the given
143  * PrintWriter. If there is a root cause, the stack trace of the root
144  * <code>Exception</code> is printed right after.
145  * </p>
146  */

147     public void printStackTrace(PrintWriter JavaDoc w) {
148         super.printStackTrace(w);
149
150         if (rootCause != null) {
151             w.print("Root cause: ");
152             rootCause.printStackTrace(w);
153         }
154     }
155
156     /**
157  * <p>
158  * This will return the root cause <code>Throwable</code>, or null
159  * if one does not exist.
160  * </p>
161  *
162  * @return <code>Throwable</code> - the wrapped <code>Throwable</code>.
163  */

164     public Throwable JavaDoc getRootCause() {
165         return rootCause;
166     }
167 }
168
Popular Tags