KickJava   Java API By Example, From Geeks To Geeks.

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


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  * A checked chained exception.
27  *
28  * @version $Id: ChainedException.java,v 1.1 2004/05/22 11:34:46 vmassol Exp $
29  */

30 public class ChainedException extends Exception JavaDoc
31 {
32     /**
33      * Original exception which caused this exception.
34      */

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

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

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

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

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

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

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