1 22 23 package org.xquark.xml.xdbc; 24 25 import java.io.PrintStream ; 26 27 import org.xml.sax.SAXException ; 28 import org.xml.sax.SAXParseException ; 29 30 36 public class XMLDBCException extends java.lang.Exception { 37 38 40 41 public static final int NO_CODE = 0; 42 43 45 46 protected int errorCode = NO_CODE; 47 48 49 protected java.lang.Throwable exception; 50 51 53 59 public XMLDBCException(int code) { 60 this(code, "", null); 61 } 62 63 69 public XMLDBCException(java.lang.String msg) { 70 this(XMLDBCException.NO_CODE, msg, null); 71 } 72 73 81 public XMLDBCException(int code, java.lang.String msg) { 82 this(code, msg, null); 83 } 84 85 93 public XMLDBCException(java.lang.String msg, java.lang.Throwable exception) { 94 this(XMLDBCException.NO_CODE, msg, exception); 95 } 96 97 107 public XMLDBCException(int code, java.lang.String msg, 108 java.lang.Throwable exception) { 109 super(msg); 110 this.errorCode = code; 111 this.exception = exception; 112 } 113 114 116 121 public int getCode() { 122 return this.errorCode; 123 } 124 125 130 public java.lang.Throwable getException() { 131 return this.exception; 132 } 133 134 140 public String getMessage() { 141 String message = super.getMessage(); 142 if ((message == null || message.length() == 0) && exception != null) 143 message = this.exception.getMessage(); 144 145 return message; 146 } 147 148 152 public static void printError(Throwable e, boolean pst) { 154 printError(e, System.err, pst); 155 } 156 157 160 public static void printError(Throwable e, PrintStream ps, boolean pst) { 162 if (e != null) { 163 if (e.getMessage() != null) { 164 165 ps.println("Exception: " + e.getMessage()); 166 } 167 168 169 if (e instanceof SAXParseException ) { 170 SAXParseException spex = (SAXParseException ) e; 171 ps.println("XML error location : " + spex.getSystemId() + " [" 172 + spex.getLineNumber() + ':' + spex.getColumnNumber() 173 + ']'); 174 } 175 176 if (pst) 177 e.printStackTrace(ps); 178 179 180 if (e instanceof XMLDBCException) 181 printError(((XMLDBCException) e).getException(), ps, pst); 182 else if (e instanceof SAXException ) 183 printError(((SAXException ) e).getException(), ps, pst); 184 } 185 } 186 187 } | Popular Tags |