KickJava   Java API By Example, From Geeks To Geeks.

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


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: ChainedError.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  * Error used as a base for creating an error that has a chain of
31  * exceptions that lead to the derived error. Very useful for interfaces
32  * where the implementation exception is not known.
33  */

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

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

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

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

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

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

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

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

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

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