1 6 package org.logicalcobwebs.proxool; 7 8 import java.io.PrintStream ; 9 import java.io.PrintWriter ; 10 11 29 public class ProxoolException extends Exception { 30 35 private Throwable cause = this; 36 37 42 public ProxoolException() { 43 super(); 44 } 45 46 54 public ProxoolException(String message) { 55 super(message); 56 } 57 58 72 public ProxoolException(String message, Throwable cause) { 73 this(message); 74 this.cause = cause; 75 } 76 77 89 public ProxoolException(Throwable cause) { 90 this(cause == null ? null : cause.toString()); 91 this.cause = cause; 92 } 93 94 106 public Throwable getCause() { 107 return (cause == this ? null : cause); 108 } 109 110 127 public synchronized Throwable initCause(Throwable cause) { 128 if (this.cause != this) { 129 throw new IllegalStateException ("Can't overwrite cause"); 130 } 131 if (cause == this) { 132 throw new IllegalArgumentException ("Self-causation not permitted"); 133 } 134 this.cause = cause; 135 return this; 136 } 137 138 145 public void printStackTrace() { 146 printStackTrace(System.err); 147 } 148 149 154 public void printStackTrace(PrintStream stream) { 155 synchronized (stream) { 156 super.printStackTrace(stream); 157 Throwable ourCause = getCause(); 158 if (ourCause != null) { 159 stream.println(); 160 stream.println("Caused by:"); 161 ourCause.printStackTrace(stream); 162 } 163 } 164 } 165 166 172 public void printStackTrace(PrintWriter writer) { 173 synchronized (writer) { 174 super.printStackTrace(writer); 175 Throwable ourCause = getCause(); 176 if (ourCause != null) { 177 writer.println(); 178 writer.println("Caused by:"); 179 ourCause.printStackTrace(writer); 180 } 181 } 182 } 183 184 } 185 | Popular Tags |