1 64 65 package com.jcorporate.expresso.kernel.exception; 66 67 import java.io.PrintStream ; 68 import java.io.PrintWriter ; 69 70 71 79 public class ChainedException 80 extends Exception { 81 private Throwable nested = null; 82 private int errorNumber = 0; 83 84 87 public ChainedException() { 88 super(); 89 } 90 91 96 public ChainedException(String s) { 97 super(s); 98 } 99 100 106 public ChainedException(String s, int newErrorNumber) { 107 super(s); 108 errorNumber = newErrorNumber; 109 } 110 111 117 public ChainedException(String message, Throwable newNested) { 118 super(message); 119 nested = newNested; 120 } 121 122 129 public ChainedException(String message, Throwable newNested, 130 int newErrorNumber) { 131 super(message); 132 nested = newNested; 133 errorNumber = newErrorNumber; 134 } 135 136 141 public ChainedException(Throwable newNested) { 142 nested = newNested; 143 } 144 145 151 public ChainedException(Throwable newNested, int newErrorNumber) { 152 nested = newNested; 153 errorNumber = newErrorNumber; 154 } 155 156 161 public String getMessage() { 162 String myMessage = super.getMessage(); 163 164 if ((myMessage == null) && (nested != null)) { 165 myMessage = ("Nested exception: " + omitPackages(nested) + ": " + 166 nested.getMessage()); 167 } 168 169 return myMessage; 170 } 171 172 178 public static String omitPackages(Object obj) { 179 int i = obj.getClass().getPackage().getName().length(); 180 if (i > 0) { 181 i++; 182 } 183 return obj.getClass().getName().substring(i); 184 } 185 186 191 public int getErrorNumber() { 192 return errorNumber; 193 } 194 195 198 public void printStackTrace() { 199 if (nested != null) { 200 nested.printStackTrace(); 201 } 202 super.printStackTrace(); 203 } 204 205 210 public void printStackTrace(PrintStream p) { 211 if (nested != null) { 212 nested.printStackTrace(p); 213 } 214 super.printStackTrace(p); 215 216 } 217 218 223 public void printStackTrace(PrintWriter p) { 224 if (nested != null) { 225 nested.printStackTrace(p); 226 } 227 super.printStackTrace(p); 228 } 229 230 235 public Throwable getNested() { 236 return nested; 237 } 238 239 } 240 | Popular Tags |