KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > snapper > api > RootException


1 package org.enhydra.snapper.api;
2
3 import java.io.PrintStream JavaDoc;
4 import java.io.PrintWriter JavaDoc;
5
6 /**
7  * This exception is base for all exceptions defined in Shark. It
8  * allows implementation of chain exceptions, and this implementation
9  * takes care if JDK1.3 or JDK1.4 is used.
10  *
11  * @author Vladimir Puskas
12  */

13 public class RootException extends Exception JavaDoc {
14    
15    private Throwable JavaDoc cause;
16    
17    /**
18     * Constructs a new exception with null as its detail message.
19     *
20     */

21    public RootException() {
22       super();
23    }
24    /**
25     * Constructs a new exception with the specified detail message.
26     *
27     * @param message the detail message.
28     *
29     */

30    public RootException(String JavaDoc message) {
31       super(message);
32    }
33    
34    /**
35     * Constructs a new exception with the specified cause.
36     *
37     * @param t the cause. A null value is permitted, and indicates that
38     * the cause is nonexistent or unknown.
39     *
40     */

41    public RootException(Throwable JavaDoc t) {
42       super(t.getMessage());
43       try {
44          initCause(t);
45       } catch (Throwable JavaDoc e) {}
46    }
47    
48    /**
49     * Constructs a new exception with the specified detail message and cause.
50     *
51     * @param message the detail message.
52     * @param t the cause. A null value is permitted, and indicates that
53     * the cause is nonexistent or unknown.
54     */

55    public RootException(String JavaDoc message, Throwable JavaDoc t) {
56       super(message);
57       try {
58          initCause(t);
59       } catch (Throwable JavaDoc e) {}
60    }
61    
62    /**
63     * Initializes the cause of this exception to the specified value.
64     *
65     * @param t the cause.
66     *
67     * @return a reference to this instance.
68     *
69     * @exception IllegalArgumentException
70     * @exception IllegalStateException
71     */

72    public Throwable JavaDoc initCause(Throwable JavaDoc t) throws IllegalArgumentException JavaDoc, IllegalStateException JavaDoc {
73       cause = t;
74       return this;
75    }
76    
77    
78    /**
79     * Returns the cause of this exception.
80     *
81     * @return a cause for this exception if any, null otherwise
82     *
83     */

84    public Throwable JavaDoc getCause() {
85       return cause;
86    }
87    
88    /**
89     * Method printStackTrace prints the stack trace to the <i>ps</i> PrintStream.
90     *
91     * @param ps PrintStream used for the output.
92     */

93    public void printStackTrace(PrintStream JavaDoc ps) {
94       if (null != cause) {
95          cause.printStackTrace(ps);
96       }
97       super.printStackTrace(ps);
98    }
99    
100    /**
101     * Method printStackTrace prints the stack trace to the <i>pw</i> PrintWriter.
102     *
103     * @param pw PrintWriter used for the output.
104     */

105    public void printStackTrace(PrintWriter JavaDoc pw) {
106       if (null != cause) {
107          cause.printStackTrace(pw);
108       }
109       super.printStackTrace(pw);
110    }
111    /**
112     * Method printStackTrace prints the stack trace to the standard error stream.
113     */

114    public void printStackTrace() {
115       printStackTrace(System.err);
116    }
117 }
Popular Tags