KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

43     public ChainedException(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
53      * exception.
54      */

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

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

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

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

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

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

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

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