001: /*
002: * ========================================================================
003: *
004: * Copyright 2001-2003 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * ========================================================================
019: */
020: package org.apache.cactus.util;
021:
022: import java.io.PrintStream;
023: import java.io.PrintWriter;
024:
025: /**
026: * A checked chained exception.
027: *
028: * @version $Id: ChainedException.java 238991 2004-05-22 11:34:50Z vmassol $
029: */
030: public class ChainedException extends Exception {
031: /**
032: * Original exception which caused this exception.
033: */
034: protected Throwable originalException;
035:
036: /**
037: * Create a <code>ChainedException</code> and set the exception error
038: * message.
039: *
040: * @param theMessage the message of the exception
041: */
042: public ChainedException(String theMessage) {
043: this (theMessage, null);
044: }
045:
046: /**
047: * Create a <code>ChainedException</code>, set the exception error
048: * message along with the exception object that caused this exception.
049: *
050: * @param theMessage the detail of the error message
051: * @param theException the original exception
052: */
053: public ChainedException(String theMessage, Throwable theException) {
054: super (theMessage);
055: this .originalException = theException;
056: }
057:
058: /**
059: * Create a <code>ChaineException</code>, and set exception object
060: * that caused this exception. The message is set by default to be the one
061: * from the original exception.
062: *
063: * @param theException the original exception
064: */
065: public ChainedException(Throwable theException) {
066: super (theException.getMessage());
067: this .originalException = theException;
068: }
069:
070: /**
071: * Print the full stack trace, including the original exception.
072: */
073: public void printStackTrace() {
074: printStackTrace(System.err);
075: }
076:
077: /**
078: * Print the full stack trace, including the original exception.
079: *
080: * @param thePs the byte stream in which to print the stack trace
081: */
082: public void printStackTrace(PrintStream thePs) {
083: super .printStackTrace(thePs);
084:
085: if (this .originalException != null) {
086: this .originalException.printStackTrace(thePs);
087: }
088: }
089:
090: /**
091: * Print the full stack trace, including the original exception.
092: *
093: * @param thePw the character stream in which to print the stack trace
094: */
095: public void printStackTrace(PrintWriter thePw) {
096: super.printStackTrace(thePw);
097:
098: if (this.originalException != null) {
099: this.originalException.printStackTrace(thePw);
100: }
101: }
102: }
|