Source code: javatools/util/CommonException.java
1 /*
2 Javatools (modified version) - Some useful general classes.
3 Copyright (C) 2002-2003 Chris Bitmead (original) Antonio Petrelli (modified)
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Contact me at: brenmcguire@users.sourceforge.net
20 */
21 package javatools.util;
22 import java.io.*;
23
24 /**
25 * A base class for other types of exceptions.
26 * @author Chris Bitmead
27 * @version 0.7
28 * @commentedby Antonio Petrelli
29 */
30 public class CommonException extends Exception {
31 /** The exception to be used.
32 */
33 Throwable nextException;
34
35 /** Creates a new CommonException
36 * @param mesg The exception message.
37 */
38 public CommonException(String mesg) {
39 super(mesg);
40 }
41 /** Creates a new CommonException
42 * @param mesg The message.
43 * @param exception The base exception.
44 */
45 public CommonException(String mesg, Throwable exception) {
46 super(mesg);
47 nextException = exception;
48 }
49 /** Creates a new CommonException.
50 * @param exception The base exception.
51 */
52 public CommonException(Throwable exception) {
53 nextException = exception;
54 }
55 /** Returns the next exception.
56 * @return The next exception.
57 */
58 public Throwable getNextException() {
59 return nextException;
60 }
61 /** Returns the exception converted into a string.
62 * @return The string that represents this exception.
63 */
64 public String toString() {
65 String rtn = super.toString();
66 if (nextException != null) {
67 rtn += " " + nextException.toString();
68 }
69 return rtn;
70 }
71 /** Returns the stack trace after this exception.
72 * @return The string representing the stack trace.
73 */
74 public StackTraceElement[] getStackTrace() {
75 /* ByteArrayOutputStream baos = new ByteArrayOutputStream();
76 PrintStream ps = new PrintStream(baos);
77 super.printStackTrace(ps);
78 if (nextException != null) {
79 nextException.printStackTrace(ps);
80 }
81 return baos.toString();
82 */
83 return super.getStackTrace();
84 }
85 /** Prints the stack trace to a print writer.
86 * @param s The print writer to use.
87 */
88 public void printStackTrace(PrintWriter s) {
89 super.printStackTrace(s);
90 if (nextException != null) {
91 nextException.printStackTrace(s);
92 }
93 }
94 /** Prints the stack trace to standard output.
95 */
96 public void printStackTrace() {
97 super.printStackTrace();
98 if (nextException != null) {
99 nextException.printStackTrace();
100 }
101 }
102 /** Prints the stack trace to a print stream.
103 * @param s The print stream to use.
104 */
105 public void printStackTrace(PrintStream s) {
106 super.printStackTrace(s);
107 if (nextException != null) {
108 nextException.printStackTrace(s);
109 }
110 }
111 }