001: /*
002: * Bossa Workflow System
003: *
004: * $Id: BossaException.java,v 1.3 2004/01/15 22:13:32 gdvieira Exp $
005: *
006: * Copyright (C) 2003,2004 OpenBR Sistemas S/C Ltda.
007: *
008: * This file is part of Bossa.
009: *
010: * Bossa is free software; you can redistribute it and/or modify it
011: * under the terms of version 2 of the GNU General Public License as
012: * published by the Free Software Foundation.
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 GNU
017: * General Public License for more details.
018: *
019: * You should have received a copy of the GNU General Public
020: * License along with this program; if not, write to the
021: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
022: * Boston, MA 02111-1307, USA.
023: */
024:
025: package com.bigbross.bossa;
026:
027: import java.io.PrintStream;
028: import java.io.PrintWriter;
029:
030: /**
031: * This class represents an exception of the Bossa system. <p>
032: *
033: * This exception also implements the behaviour of a nested (or chained)
034: * exception, such as the <code>Throwable</code> class in Java 1.4.
035: * This is an exception which may contain another throwable which
036: * caused it to get thrown. <p>
037: *
038: * @author <a href="http://www.bigbross.com">BigBross Team</a>
039: */
040: public class BossaException extends Exception {
041:
042: private Throwable cause;
043:
044: private boolean causeRead;
045:
046: /**
047: * Constructs a new <code>BossaException</code> object with
048: * <code>null</code> as its detail message. <p>
049: */
050: public BossaException() {
051: super ();
052: this .cause = null;
053: }
054:
055: /**
056: * Constructs a new <code>BossaException</code> object with the
057: * specified detail message. <p>
058: *
059: * @param message the detail message.
060: */
061: public BossaException(String message) {
062: super (message);
063: this .cause = null;
064: }
065:
066: /**
067: * Constructs a new <code>BossaException</code> object with the
068: * specified detail message and cause. <p>
069: *
070: * @param message the detail message.
071: * @param cause the cause.
072: */
073: public BossaException(String message, Throwable cause) {
074: super (message);
075: this .cause = cause;
076: }
077:
078: /**
079: * Constructs a new <code>BossaException</code> object with the
080: * specified cause and a detail message of
081: * <code>cause.toString()</code>. <p>
082: *
083: * @param cause the cause.
084: */
085: public BossaException(Throwable cause) {
086: super (cause.toString());
087: this .cause = cause;
088: }
089:
090: /**
091: * Returns the cause of this <code>BossaException</code>. The
092: * cause is the throwable that caused this
093: * <code>BossaException</code> object to get thrown. <p>
094: *
095: * @return the cause.
096: */
097: public Throwable getCause() {
098: this .causeRead = true;
099: return this .cause;
100: }
101:
102: /**
103: * Prints this <code>BossaException</code> object and its
104: * backtrace to the standard error stream. <p>
105: */
106: public void printStackTrace() {
107: printStackTrace(System.err);
108: }
109:
110: /**
111: * Prints this <code>BossaException</code> object and its
112: * backtrace to the specified print stream. <p>
113: *
114: * @param ps <code>PrintStream</code> object to use for output.
115: */
116: public void printStackTrace(PrintStream ps) {
117: this .causeRead = false;
118: super .printStackTrace(ps);
119: if (cause != null && this .causeRead == false) {
120: ps.print("Caused by: ");
121: cause.printStackTrace(ps);
122: }
123: }
124:
125: /**
126: * Prints this <code>BossaException</code> object and its
127: * backtrace to the specified print writer. <p>
128: *
129: * @param pw <code>PrintWriter</code> object to use for output.
130: */
131: public void printStackTrace(PrintWriter pw) {
132: this .causeRead = false;
133: super .printStackTrace(pw);
134: if (cause != null && this .causeRead == false) {
135: pw.print("Caused by: ");
136: cause.printStackTrace(pw);
137: }
138: }
139: }
|