View Javadoc
1   package org.exolab.castor.core.exceptions;
2   
3   import java.io.PrintStream;
4   import java.io.PrintWriter;
5   
6   public final class CastorIllegalStateException extends IllegalStateException {
7     /** SerialVersionUID */
8     private static final long serialVersionUID = 2351884252990815335L;
9   
10    /** The cause for this exception. */
11    private Throwable _cause;
12  
13    public CastorIllegalStateException() {
14      super();
15    }
16  
17    public CastorIllegalStateException(final String message) {
18      super(message);
19    }
20  
21    public CastorIllegalStateException(final Throwable cause) {
22      super();
23      _cause = cause;
24    }
25  
26    public CastorIllegalStateException(final String message, final Throwable cause) {
27      super(message);
28      _cause = cause;
29    }
30  
31    /**
32     * Match the JDK 1.4 Throwable version of getCause() on JDK<1.4 systems.
33     * 
34     * @return The throwable cause of this exception.
35     */
36    public Throwable getCause() {
37      return _cause;
38    }
39  
40    /**
41     * Print a stack trace to stderr.
42     */
43    public void printStackTrace() {
44      // Print the stack trace for this exception.
45      super.printStackTrace();
46  
47      if (_cause != null) {
48        System.err.print("Caused by: ");
49        _cause.printStackTrace();
50      }
51    }
52  
53    /**
54     * Print a stack trace to the specified PrintStream.
55     * 
56     * @param s The PrintStream to print a stack trace to.
57     */
58    public void printStackTrace(final PrintStream s) {
59      // Print the stack trace for this exception.
60      super.printStackTrace(s);
61  
62      if (_cause != null) {
63        s.print("Caused by: ");
64        _cause.printStackTrace(s);
65      }
66    }
67  
68    /**
69     * Print a stack trace to the specified PrintWriter.
70     * 
71     * @param w The PrintWriter to print a stack trace to.
72     */
73    public void printStackTrace(final PrintWriter w) {
74      // Print the stack trace for this exception.
75      super.printStackTrace(w);
76  
77      if (_cause != null) {
78        w.print("Caused by: ");
79        _cause.printStackTrace(w);
80      }
81    }
82  }