1 3 package jodd.util; 4 5 import java.io.PrintWriter ; 6 import java.io.PrintStream ; 7 8 11 public class UncheckedException extends RuntimeException { 12 13 protected final Throwable cause; 14 15 17 public UncheckedException(Throwable t) { 18 super(t.getMessage()); 19 cause = t; 20 } 21 22 public UncheckedException() { 23 super(); 24 cause = null; 25 } 26 27 public UncheckedException(String message) { 28 super(message); 29 cause = null; 30 } 31 32 public UncheckedException(String message, Throwable t) { 33 super(message, t); 34 cause = t; 35 } 36 37 39 public void printStackTrace() { 40 printStackTrace(System.err); 41 } 42 43 public void printStackTrace(PrintStream printStream) { 44 synchronized (printStream) { 45 printStream.print(getClass().getName() + ": "); 46 super.printStackTrace(printStream); 47 } 48 } 49 50 public void printStackTrace(PrintWriter printWriter) { 51 synchronized (printWriter) { 52 printWriter.print(getClass().getName() + ": "); 53 super.printStackTrace(printWriter); 54 } 55 } 56 57 59 62 public void rethrow() throws Throwable { 63 if (cause == null) { 64 return; 65 } 66 throw cause; 67 } 68 69 72 public Throwable getCause() { 73 return cause; 74 } 75 76 } 77 | Popular Tags |