KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > util > throwable > v1 > ChainableException


1 /*
2  * @(#)ChainableException.java
3  *
4  * Copyright (C) 2002-2003 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Part of the GroboUtils package at:
9  * http://groboutils.sourceforge.net
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in
19  * all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  */

29 package net.sourceforge.groboutils.util.throwable.v1;
30
31
32 import java.io.PrintStream JavaDoc;
33 import java.io.PrintWriter JavaDoc;
34
35
36 /**
37  * General chainable exception, for pseudo-JDK 1.4 support.
38  *
39  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
40  * @version $Date: 2003/09/23 19:54:07 $
41  * @since July 7, 2002
42  */

43 public class ChainableException extends Exception JavaDoc
44         implements IChainableException
45 {
46     /**
47      * @serial
48      */

49     private ChainableExceptionHelper ceh;
50     
51     
52     public ChainableException()
53     {
54         super();
55         this.ceh = new ChainableExceptionHelper( this );
56     }
57     
58     
59     public ChainableException( String JavaDoc message )
60     {
61         super( message );
62         this.ceh = new ChainableExceptionHelper( this );
63     }
64     
65     
66     public ChainableException( Throwable JavaDoc cause )
67     {
68         super();
69         this.ceh = new ChainableExceptionHelper( this, cause );
70     }
71     
72     
73     public ChainableException( Throwable JavaDoc cause, String JavaDoc message )
74     {
75         this( message, cause );
76     }
77     
78     
79     public ChainableException( String JavaDoc message, Throwable JavaDoc cause )
80     {
81         super( message );
82         this.ceh = new ChainableExceptionHelper( this, cause );
83     }
84     
85     
86     /**
87      * JDK 1.4 compatible method.
88      * <P>
89      * <i>from the JDK 1.4 documentation:</i>
90      * <BLOCKQUOTE>
91      * Returns the cause of this throwable or <tt>null</tt> if the cause is
92      * nonexistent or unknown. (The cause is the throwable that caused this
93      * throwable to get thrown.)
94      * <P>
95      * This implementation returns the cause that was supplied via one of the
96      * constructors requiring a <tt>Throwable</tt>, or that was set after
97      * creation with the <tt>initCause( Throwable )</tt> method. While it is
98      * typically unnecessary to override this method, a subclass can override
99      * it to return a cause set by some other means. This is appropriate for a
100      * "legacy chained throwable" that predates the addition of chained
101      * exceptions to <tt>Throwable</tt>. Note that it is not necessary to
102      * override any of the <tt>PrintStackTrace</tt> methods, all of which
103      * invoke the getCause method to determine the cause of a throwable.
104      * </BLOCKQUOTE>
105      *
106      * @return the cause of this throwable or <tt>null</tt> if the cause is
107      * nonexistent or unknown.
108      */

109     public synchronized Throwable JavaDoc getCause()
110     {
111         return this.ceh.getCause();
112     }
113     
114     
115     /**
116      * JDK 1.4 compatible method.
117      * <P>
118      * <i>from the JDK 1.4 documentation:</i>
119      * <BLOCKQUOTE>
120      * Initializes the cause of this throwable to the specified value.
121      * (The cause is the throwable that caused this throwable to get thrown.)
122      * <P>
123      * This method can be called at most once. It is generally called from
124      * within the constructor, or immediately after creating the throwable.
125      * If this throwable was created with Throwable(Throwable) or
126      * Throwable(String,Throwable), this method cannot be called even once.
127      * </BLOCKQUOTE>
128      *
129      * @param cause the cause (which is saved for later retrieval by the
130      * getCause() method). (A null value is permitted, and indicates
131      * that the cause is nonexistent or unknown.)
132      * @return a reference to this Throwable instance.
133      * @exception IllegalArgumentException if cause is this throwable.
134      * (A throwable cannot be its own cause.)
135      * @exception IllegalStateException if this throwable was created with
136      * Throwable(Throwable) or Throwable(String,Throwable), or this
137      * method has already been called on this throwable.
138      */

139     public synchronized Throwable JavaDoc initCause( Throwable JavaDoc cause )
140     {
141         return this.ceh.initCause( cause );
142     }
143     
144     
145     /**
146      * For non-JDK 1.4 compatible VMs, this overrides the original behavior
147      * to describe the underlying cause. Special logic is performed to ensure
148      * that no JDK 1.4 VM is being used when the inner exception is displayed
149      * (in order to prevent double printing).
150      */

151     public void printStackTrace( PrintStream JavaDoc ps )
152     {
153         this.ceh.printStackTrace( ps );
154     }
155     
156     
157     
158     /**
159      * For non-JDK 1.4 compatible VMs, this overrides the original behavior
160      * to describe the underlying cause. Special logic is performed to ensure
161      * that no JDK 1.4 VM is being used when the inner exception is displayed
162      * (in order to prevent double printing).
163      */

164     public void printStackTrace( PrintWriter JavaDoc pw )
165     {
166         this.ceh.printStackTrace( pw );
167     }
168 }
169
170
Popular Tags