KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > error > ChainedRuntimeException


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: ChainedRuntimeException.java,v 1.2 2005/01/26 08:29:24 jkjome Exp $
22  */

23
24 package org.enhydra.error;
25
26 import java.io.PrintStream JavaDoc;
27 import java.io.PrintWriter JavaDoc;
28
29 /**
30  * RuntimeException used as a base for creating an exception that has a chain
31  * of exceptions that lead to the derived exception. Very useful for
32  * interfaces where the implementation exception is not known.
33  */

34 public class ChainedRuntimeException extends RuntimeException JavaDoc
35                                      implements ChainedThrowable {
36     /** Causing exception, or null if none */
37     private Throwable JavaDoc fCause;
38
39     /**
40      * Construct an exception without a specified cause.
41      *
42      * @param msg The message associated with the exception.
43      */

44     protected ChainedRuntimeException(String JavaDoc msg) {
45         super(msg);
46         fCause = null;
47     }
48
49     /**
50      * Construct an exception with an associated causing exception.
51      *
52      * @param msg The message associated with the exception.
53      * @param cause The error or exception that cause this
54      * exception.
55      */

56     protected ChainedRuntimeException(String JavaDoc msg,
57                                       Throwable JavaDoc cause) {
58         super(msg);
59         fCause = cause;
60     }
61
62     /**
63      * Construct an exception from a causing exception.
64      *
65      * @param cause The error or exception that cause this
66      * exception. The message will be take be this object's
67      * messasge.
68      */

69     protected ChainedRuntimeException(Throwable JavaDoc cause) {
70         super(ChainedThrowableSupport.makeMessage(cause));
71         fCause = cause;
72     }
73
74     /**
75      * Return the message associated with this exception. If causes
76      * are included, they will be appended to the message.
77      */

78     public String JavaDoc getMessage() {
79         return ChainedThrowableSupport.getMessage(this, super.getMessage());
80     }
81
82     /**
83      * Creates a localized description of this exception.
84      */

85     public String JavaDoc getLocalizedMessage() {
86         return ChainedThrowableSupport.getLocalizedMessage(this, super.getLocalizedMessage());
87     }
88
89     /**
90      * Get the causing exception associated with this exception.
91      * @return The causing exception or null if no cause is specified.
92      */

93     public Throwable JavaDoc getCause() {
94         return fCause;
95     }
96
97     /**
98      * Prints this exception and its backtrace, and the causes and their stack
99      * traces to the standard error stream.
100      */

101     public void printStackTrace() {
102         super.printStackTrace();
103         ChainedThrowableSupport.printCauseTrace(this);
104     }
105
106     /**
107      * Prints this exception and its backtrace, and the causes and their stack
108      * traces to the e specified print stream.
109      */

110     public void printStackTrace(PrintStream JavaDoc s) {
111         super.printStackTrace(s);
112         ChainedThrowableSupport.printCauseTrace(this, s);
113     }
114
115     /**
116      * Prints this exception and its backtrace, and the causes and their stack
117      * traces to the e specified print writer.
118      */

119     public void printStackTrace(PrintWriter JavaDoc s) {
120         super.printStackTrace(s);
121         ChainedThrowableSupport.printCauseTrace(this, s);
122     }
123 }
124
Popular Tags