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: * Represent an exception that should stop the running test. It is a runtime
027: * exception but it will be caught by JUnit so the application will not stop.
028: * The test will be reported as failed. It implements chaining.
029: *
030: * @version $Id: ChainedRuntimeException.java 238991 2004-05-22 11:34:50Z vmassol $
031: */
032: public class ChainedRuntimeException extends RuntimeException {
033: /**
034: * Original exception which caused this exception.
035: */
036: protected Throwable originalException;
037:
038: /**
039: * Create a <code>ChainedRuntimeException</code> and set the exception
040: * error message.
041: *
042: * @param theMessage the message of the exception
043: */
044: public ChainedRuntimeException(String theMessage) {
045: this (theMessage, null);
046: }
047:
048: /**
049: * Create a <code>ChainedRuntimeException</code>, set the exception error
050: * message along with the exception object that caused this exception.
051: *
052: * @param theMessage the detail of the error message
053: * @param theException the original exception
054: */
055: public ChainedRuntimeException(String theMessage,
056: Throwable theException) {
057: super (theMessage);
058: this .originalException = theException;
059: }
060:
061: /**
062: * Create a <code>ChainedRuntimeException</code>, and set exception object
063: * that caused this exception. The message is set by default to be the one
064: * from the original exception.
065: *
066: * @param theException the original exception
067: */
068: public ChainedRuntimeException(Throwable theException) {
069: super (theException.getMessage());
070: this .originalException = theException;
071: }
072:
073: /**
074: * Print the full stack trace, including the original exception.
075: */
076: public void printStackTrace() {
077: printStackTrace(System.err);
078: }
079:
080: /**
081: * Print the full stack trace, including the original exception.
082: *
083: * @param thePs the byte stream in which to print the stack trace
084: */
085: public void printStackTrace(PrintStream thePs) {
086: super .printStackTrace(thePs);
087:
088: if (this .originalException != null) {
089: this .originalException.printStackTrace(thePs);
090: }
091: }
092:
093: /**
094: * Print the full stack trace, including the original exception.
095: *
096: * @param thePw the character stream in which to print the stack trace
097: */
098: public void printStackTrace(PrintWriter thePw) {
099: super.printStackTrace(thePw);
100:
101: if (this.originalException != null) {
102: this.originalException.printStackTrace(thePw);
103: }
104: }
105: }
|