1 16 package com.ibatis.common.jdbc.exception; 17 18 import java.sql.SQLException ; 19 20 23 public class NestedSQLException extends SQLException { 24 25 private static final String CAUSED_BY = "\nCaused by: "; 26 27 private Throwable cause = null; 28 29 34 public NestedSQLException(String msg) { 35 super(msg); 36 } 37 38 44 public NestedSQLException(String reason, String SQLState) { 45 super(reason, SQLState); 46 } 47 48 55 public NestedSQLException(String reason, String SQLState, int vendorCode) { 56 super(reason, SQLState, vendorCode); 57 } 58 59 64 public NestedSQLException(String msg, Throwable cause) { 65 super(msg); 66 this.cause = cause; 67 } 68 69 76 public NestedSQLException(String reason, String SQLState, Throwable cause) { 77 super(reason, SQLState); 78 this.cause = cause; 79 } 80 81 88 public NestedSQLException(String reason, String SQLState, int vendorCode, Throwable cause) { 89 super(reason, SQLState, vendorCode); 90 this.cause = cause; 91 } 92 93 97 public NestedSQLException(Throwable cause) { 98 super(); 99 this.cause = cause; 100 } 101 102 105 public Throwable getCause() { 106 return cause; 107 } 108 109 public String toString() { 110 if (cause == null) { 111 return super.toString(); 112 } else { 113 return super.toString() + CAUSED_BY + cause.toString(); 114 } 115 } 116 117 public void printStackTrace() { 118 super.printStackTrace(); 119 if (cause != null) { 120 System.err.println(CAUSED_BY); 121 cause.printStackTrace(); 122 } 123 } 124 125 public void printStackTrace(java.io.PrintStream ps) { 126 super.printStackTrace(ps); 127 if (cause != null) { 128 ps.println(CAUSED_BY); 129 cause.printStackTrace(ps); 130 } 131 } 132 133 public void printStackTrace(java.io.PrintWriter pw) { 134 super.printStackTrace(pw); 135 if (cause != null) { 136 pw.println(CAUSED_BY); 137 cause.printStackTrace(pw); 138 } 139 } 140 141 142 } 143 | Popular Tags |