1 2 18 19 22 package org.quartz; 23 24 import java.io.PrintStream ; 25 import java.io.PrintWriter ; 26 27 import org.quartz.utils.ExceptionHelper; 28 29 41 public class SchedulerException extends Exception { 42 43 50 51 public static final int ERR_UNSPECIFIED = 0; 52 53 public static final int ERR_BAD_CONFIGURATION = 50; 54 55 public static final int ERR_TIME_BROKER_FAILURE = 70; 56 57 public static final int ERR_CLIENT_ERROR = 100; 58 59 public static final int ERR_COMMUNICATION_FAILURE = 200; 60 61 public static final int ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION = 210; 62 63 public static final int ERR_PERSISTENCE = 400; 64 65 public static final int ERR_PERSISTENCE_JOB_DOES_NOT_EXIST = 410; 66 67 public static final int ERR_PERSISTENCE_CALENDAR_DOES_NOT_EXIST = 420; 68 69 public static final int ERR_PERSISTENCE_TRIGGER_DOES_NOT_EXIST = 430; 70 71 public static final int ERR_PERSISTENCE_CRITICAL_FAILURE = 499; 72 73 public static final int ERR_THREAD_POOL = 500; 74 75 public static final int ERR_THREAD_POOL_EXHAUSTED = 510; 76 77 public static final int ERR_THREAD_POOL_CRITICAL_FAILURE = 599; 78 79 public static final int ERR_JOB_LISTENER = 600; 80 81 public static final int ERR_JOB_LISTENER_NOT_FOUND = 610; 82 83 public static final int ERR_TRIGGER_LISTENER = 700; 84 85 public static final int ERR_TRIGGER_LISTENER_NOT_FOUND = 710; 86 87 public static final int ERR_JOB_EXECUTION_THREW_EXCEPTION = 800; 88 89 public static final int ERR_TRIGGER_THREW_EXCEPTION = 850; 90 91 98 99 private Throwable cause; 100 101 private int errorCode = ERR_UNSPECIFIED; 102 103 110 111 public SchedulerException() { 112 super(); 113 } 114 115 public SchedulerException(String msg) { 116 super(msg); 117 } 118 119 public SchedulerException(String msg, int errorCode) { 120 super(msg); 121 setErrorCode(errorCode); 122 } 123 124 public SchedulerException(Throwable cause) { 125 super(cause.toString()); 126 setCause(cause); 127 } 128 129 public SchedulerException(String msg, Throwable cause) { 130 super(msg); 131 setCause(cause); 132 } 133 134 public SchedulerException(String msg, Throwable cause, int errorCode) { 135 super(msg); 136 setCause(cause); 137 setErrorCode(errorCode); 138 } 139 140 private void setCause(Throwable cause) { 141 if (ExceptionHelper.supportsNestedThrowable()) { 142 ExceptionHelper.setCause(this, cause); 143 } else { 144 this.cause = cause; 145 } 146 } 147 148 155 156 168 public Throwable getUnderlyingException() { 169 return (ExceptionHelper.supportsNestedThrowable()) ? 170 ExceptionHelper.getCause(this) : cause; 171 } 172 173 184 public int getErrorCode() { 185 return errorCode; 186 } 187 188 200 public void setErrorCode(int errorCode) { 201 this.errorCode = errorCode; 202 } 203 204 210 public boolean isPersistenceError() { 211 return (errorCode >= ERR_PERSISTENCE && errorCode <= ERR_PERSISTENCE + 99); 212 } 213 214 220 public boolean isThreadPoolError() { 221 return (errorCode >= ERR_THREAD_POOL && errorCode <= ERR_THREAD_POOL + 99); 222 } 223 224 230 public boolean isJobListenerError() { 231 return (errorCode >= ERR_JOB_LISTENER && errorCode <= ERR_JOB_LISTENER + 99); 232 } 233 234 240 public boolean isTriggerListenerError() { 241 return (errorCode >= ERR_TRIGGER_LISTENER && errorCode <= ERR_TRIGGER_LISTENER + 99); 242 } 243 244 250 public boolean isClientError() { 251 return (errorCode >= ERR_CLIENT_ERROR && errorCode <= ERR_CLIENT_ERROR + 99); 252 } 253 254 260 public boolean isConfigurationError() { 261 return (errorCode >= ERR_BAD_CONFIGURATION && errorCode <= ERR_BAD_CONFIGURATION + 49); 262 } 263 264 public String toString() { 265 Throwable cause = getUnderlyingException(); 266 if (cause == null || cause == this) { 267 return super.toString(); 268 } else { 269 return super.toString() + " [See nested exception: " + cause + "]"; 270 } 271 } 272 273 283 public void printStackTrace() { 284 printStackTrace(System.err); 285 } 286 287 300 public void printStackTrace(PrintStream out) { 301 super.printStackTrace(out); 302 303 if (cause != null) { 304 synchronized (out) { 305 out.println("* Nested Exception (Underlying Cause) ---------------"); 306 cause.printStackTrace(out); 307 } 308 } 309 } 310 311 324 public void printStackTrace(PrintWriter out) { 325 super.printStackTrace(out); 326 327 if (cause != null) { 328 synchronized (out) { 329 out.println("* Nested Exception (Underlying Cause) ---------------"); 330 cause.printStackTrace(out); 331 } 332 } 333 } 334 335 } 336 | Popular Tags |