1 16 package com.ibatis.common.exception; 17 18 21 22 public class NestedRuntimeException extends RuntimeException { 23 24 private static final String CAUSED_BY = "\nCaused by: "; 25 26 private Throwable cause = null; 27 28 31 public NestedRuntimeException() { 32 } 33 34 39 public NestedRuntimeException(String msg) { 40 super(msg); 41 } 42 43 48 public NestedRuntimeException(Throwable cause) { 49 super(); 50 this.cause = cause; 51 } 52 53 59 public NestedRuntimeException(String msg, Throwable cause) { 60 super(msg); 61 this.cause = cause; 62 } 63 64 69 public Throwable getCause() { 70 return cause; 71 } 72 73 78 public String toString() { 79 if (cause == null) { 80 return super.toString(); 81 } else { 82 return super.toString() + CAUSED_BY + cause.toString(); 83 } 84 } 85 86 89 public void printStackTrace() { 90 super.printStackTrace(); 91 if (cause != null) { 92 System.err.println(CAUSED_BY); 93 cause.printStackTrace(); 94 } 95 } 96 97 102 public void printStackTrace(java.io.PrintStream ps) { 103 super.printStackTrace(ps); 104 if (cause != null) { 105 ps.println(CAUSED_BY); 106 cause.printStackTrace(ps); 107 } 108 } 109 110 115 public void printStackTrace(java.io.PrintWriter pw) { 116 super.printStackTrace(pw); 117 if (cause != null) { 118 pw.println(CAUSED_BY); 119 cause.printStackTrace(pw); 120 } 121 } 122 123 } 124 | Popular Tags |