001: package org.enhydra.shark.api;
002:
003: import java.io.PrintStream;
004: import java.io.PrintWriter;
005:
006: /**
007: * This Error allows implementation of chain exceptions, and this implementation
008: * takes care if JDK1.3 or JDK1.4 is used.
009: *
010: * @author Vladimir Puskas
011: * @author Sasa Bojanic
012: */
013: public class RootError extends Error {
014:
015: private Throwable cause;
016:
017: /**
018: * Constructs a new exception with null as its detail message.
019: *
020: */
021: public RootError() {
022: super ();
023: }
024:
025: /**
026: * Constructs a new exception with the specified detail message.
027: *
028: * @param message the detail message.
029: *
030: */
031: public RootError(String message) {
032: super (message);
033: }
034:
035: /**
036: * Constructs a new exception with the specified cause.
037: *
038: * @param t the cause. A null value is permitted, and indicates that
039: * the cause is nonexistent or unknown.
040: *
041: */
042: public RootError(Throwable t) {
043: super (t.getMessage());
044: try {
045: initCause(t);
046: } catch (Throwable e) {
047: }
048: }
049:
050: /**
051: * Constructs a new exception with the specified detail message and cause.
052: *
053: * @param message the detail message.
054: * @param t the cause. A null value is permitted, and indicates that
055: * the cause is nonexistent or unknown.
056: */
057: public RootError(String message, Throwable t) {
058: super (message);
059: try {
060: initCause(t);
061: } catch (Throwable e) {
062: }
063: }
064:
065: /**
066: * Initializes the cause of this exception to the specified value.
067: *
068: * @param t the cause.
069: *
070: * @return a reference to this instance.
071: *
072: * @exception IllegalArgumentException
073: * @exception IllegalStateException
074: */
075: public Throwable initCause(Throwable t)
076: throws IllegalArgumentException, IllegalStateException {
077: cause = t;
078: return this ;
079: }
080:
081: /**
082: * Returns the cause of this exception.
083: *
084: * @return a cause for this exception if any, null otherwise
085: *
086: */
087: public Throwable getCause() {
088: return cause;
089: }
090:
091: /**
092: * Method printStackTrace prints the stack trace to the <i>ps</i> PrintStream.
093: *
094: * @param ps PrintStream used for the output.
095: */
096: public void printStackTrace(PrintStream ps) {
097: if (null != cause) {
098: cause.printStackTrace(ps);
099: }
100: super .printStackTrace(ps);
101: }
102:
103: /**
104: * Method printStackTrace prints the stack trace to the <i>pw</i> PrintWriter.
105: *
106: * @param pw PrintWriter used for the output.
107: */
108: public void printStackTrace(PrintWriter pw) {
109: if (null != cause) {
110: cause.printStackTrace(pw);
111: }
112: super .printStackTrace(pw);
113: }
114:
115: /**
116: * Method printStackTrace prints the stack trace to the standard error stream.
117: */
118: public void printStackTrace() {
119: printStackTrace(System.err);
120: }
121: }
|