KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > util > ChainedRuntimeException


1 /*
2  * ========================================================================
3  *
4  * Copyright 2001-2003 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * ========================================================================
19  */

20 package org.apache.cactus.util;
21
22 import java.io.PrintStream JavaDoc;
23 import java.io.PrintWriter JavaDoc;
24
25 /**
26  * Represent an exception that should stop the running test. It is a runtime
27  * exception but it will be caught by JUnit so the application will not stop.
28  * The test will be reported as failed. It implements chaining.
29  *
30  * @version $Id: ChainedRuntimeException.java,v 1.1 2004/05/22 11:34:46 vmassol Exp $
31  */

32 public class ChainedRuntimeException extends RuntimeException JavaDoc
33 {
34     /**
35      * Original exception which caused this exception.
36      */

37     protected Throwable JavaDoc originalException;
38
39     /**
40      * Create a <code>ChainedRuntimeException</code> and set the exception
41      * error message.
42      *
43      * @param theMessage the message of the exception
44      */

45     public ChainedRuntimeException(String JavaDoc theMessage)
46     {
47         this(theMessage, null);
48     }
49
50     /**
51      * Create a <code>ChainedRuntimeException</code>, set the exception error
52      * message along with the exception object that caused this exception.
53      *
54      * @param theMessage the detail of the error message
55      * @param theException the original exception
56      */

57     public ChainedRuntimeException(String JavaDoc theMessage, Throwable JavaDoc theException)
58     {
59         super(theMessage);
60         this.originalException = theException;
61     }
62
63     /**
64      * Create a <code>ChainedRuntimeException</code>, and set exception object
65      * that caused this exception. The message is set by default to be the one
66      * from the original exception.
67      *
68      * @param theException the original exception
69      */

70     public ChainedRuntimeException(Throwable JavaDoc theException)
71     {
72         super(theException.getMessage());
73         this.originalException = theException;
74     }
75
76     /**
77      * Print the full stack trace, including the original exception.
78      */

79     public void printStackTrace()
80     {
81         printStackTrace(System.err);
82     }
83
84     /**
85      * Print the full stack trace, including the original exception.
86      *
87      * @param thePs the byte stream in which to print the stack trace
88      */

89     public void printStackTrace(PrintStream JavaDoc thePs)
90     {
91         super.printStackTrace(thePs);
92
93         if (this.originalException != null)
94         {
95             this.originalException.printStackTrace(thePs);
96         }
97     }
98
99     /**
100      * Print the full stack trace, including the original exception.
101      *
102      * @param thePw the character stream in which to print the stack trace
103      */

104     public void printStackTrace(PrintWriter JavaDoc thePw)
105     {
106         super.printStackTrace(thePw);
107
108         if (this.originalException != null)
109         {
110             this.originalException.printStackTrace(thePw);
111         }
112     }
113 }
114
Popular Tags