1 4 package org.smartlib.pool.core; 5 6 import java.sql.SQLException ; 7 14 15 public class ConnectionPoolException extends SQLException { 16 17 private Throwable previousException = null; 18 protected String message = null; 19 private Throwable nextException; 20 Debugger debug = 21 new Debugger("org.smartlib.pool.core.ConnectionPoolException", true); 22 23 24 ConnectionPoolException() { 25 26 super(); 27 28 } 29 30 31 ConnectionPoolException(String messageId){ 32 33 super(messageId); 34 message = messageId; 35 debug.print("Exception Created:" + messageId); 36 37 } 38 39 ConnectionPoolException(String messageId ,Throwable prevException) { 40 41 super(messageId); 42 if((prevException instanceof ConnectionPoolException) 43 ||(message==null)) 44 message = messageId; 45 this.previousException = prevException; 46 debug.print("Exception Created: " + messageId); 47 debug.writeException(this); 48 49 } 50 51 Throwable getPreviousException() { 52 53 return previousException; 54 55 } 56 57 62 public void printStackTrace() { 63 64 super.printStackTrace(); 65 if (previousException != null) { 66 System.err.println("Caused by Prev: "); 67 previousException.printStackTrace(); 68 } 69 if (nextException != null) { 70 System.err.println("Caused by Next: "); 71 nextException.printStackTrace(); 72 } 73 74 } 75 76 83 public void printStackTrace(java.io.PrintStream ps) { 84 85 if(ps == null) { 86 System.err.println("PrintStream passed to printStackTrace method is null."); 87 printStackTrace(); 88 } 89 super.printStackTrace(ps); 90 if (previousException != null) { 91 ps.println("Caused by:"); 92 previousException.printStackTrace(ps); 93 } 94 95 } 96 97 100 public String getMessageId() { 101 102 if(message==null) 103 return null; 104 int index = message.indexOf(":"); 105 int len = message.length(); 106 107 if(index<=0) 108 return null; 109 return message.substring(0,index); 110 111 } 112 113 String getRootMessageId() { 114 ConnectionPoolException exp = null; 115 Throwable prevExp = this; 116 while((prevExp!=null)&&(prevExp instanceof ConnectionPoolException)) { 117 exp = (ConnectionPoolException)prevExp; 118 prevExp = exp.previousException; 119 } 120 if(exp == null) 121 return null; 122 String message = exp.message; 123 if(message==null) 124 return null; 125 int index = message.indexOf(":"); 126 int len = message.length(); 127 128 if(index<=0) 129 return null; 130 return message.substring(0,index); 131 132 } 133 134 135 142 public void printStackTrace(java.io.PrintWriter pw) { 143 144 if(pw == null) { 145 System.err.println("PrintWriter passed to printStackTrace method is null."); 146 printStackTrace(); 147 } 148 super.printStackTrace(pw); 149 if (previousException != null) { 150 pw.println("Caused by:"); 151 previousException.printStackTrace(pw); 152 } 153 154 } 155 156 157 } 158 | Popular Tags |