2011/08/05 - Jakarta Cactus has been retired.

For more information, please explore the Attic.

View Javadoc

1   /* 
2    * ========================================================================
3    * 
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   * 
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * 
19   * ========================================================================
20   */
21  package org.apache.cactus.util;
22  
23  import java.io.PrintStream;
24  import java.io.PrintWriter;
25  
26  /**
27   * Represent an exception that should stop the running test. It is a runtime
28   * exception but it will be caught by JUnit so the application will not stop.
29   * The test will be reported as failed. It implements chaining.
30   *
31   * @version $Id: ChainedRuntimeException.java 238991 2004-05-22 11:34:50Z vmassol $
32   */
33  public class ChainedRuntimeException extends RuntimeException
34  {
35      /**
36       * Original exception which caused this exception.
37       */
38      protected Throwable originalException;
39  
40      /**
41       * Create a <code>ChainedRuntimeException</code> and set the exception
42       * error message.
43       *
44       * @param theMessage the message of the exception
45       */
46      public ChainedRuntimeException(String theMessage)
47      {
48          this(theMessage, null);
49      }
50  
51      /**
52       * Create a <code>ChainedRuntimeException</code>, set the exception error
53       * message along with the exception object that caused this exception.
54       *
55       * @param theMessage the detail of the error message
56       * @param theException the original exception
57       */
58      public ChainedRuntimeException(String theMessage, Throwable theException)
59      {
60          super(theMessage);
61          this.originalException = theException;
62      }
63  
64      /**
65       * Create a <code>ChainedRuntimeException</code>, and set exception object
66       * that caused this exception. The message is set by default to be the one
67       * from the original exception.
68       *
69       * @param theException the original exception
70       */
71      public ChainedRuntimeException(Throwable theException)
72      {
73          super(theException.getMessage());
74          this.originalException = theException;
75      }
76  
77      /**
78       * Print the full stack trace, including the original exception.
79       */
80      public void printStackTrace()
81      {
82          printStackTrace(System.err);
83      }
84  
85      /**
86       * Print the full stack trace, including the original exception.
87       *
88       * @param thePs the byte stream in which to print the stack trace
89       */
90      public void printStackTrace(PrintStream thePs)
91      {
92          super.printStackTrace(thePs);
93  
94          if (this.originalException != null)
95          {
96              this.originalException.printStackTrace(thePs);
97          }
98      }
99  
100     /**
101      * Print the full stack trace, including the original exception.
102      *
103      * @param thePw the character stream in which to print the stack trace
104      */
105     public void printStackTrace(PrintWriter thePw)
106     {
107         super.printStackTrace(thePw);
108 
109         if (this.originalException != null)
110         {
111             this.originalException.printStackTrace(thePw);
112         }
113     }
114 }