1 61 62 package org.jaxen.saxpath; 63 64 import java.io.PrintStream ; 65 import java.io.PrintWriter ; 66 67 71 public class SAXPathException extends Exception 72 { 73 74 static double javaVersion = 1.4; 75 76 static { 77 try { 78 String versionString = System.getProperty("java.version"); 79 versionString = versionString.substring(0, 3); 80 javaVersion = Double.valueOf(versionString).doubleValue(); 81 } 82 catch (Exception ex) { 83 } 86 } 87 88 92 public SAXPathException(String message) 93 { 94 super( message ); 95 } 96 97 101 public SAXPathException(Throwable cause) 102 { 103 super ( cause.getMessage() ); 104 initCause(cause); 105 } 106 107 114 public SAXPathException(String message, Throwable cause) { 115 super( message ); 116 initCause(cause); 117 } 118 119 120 private Throwable cause; 121 private boolean causeSet = false; 122 123 130 public Throwable getCause() { 131 return cause; 132 } 133 134 135 144 public Throwable initCause(Throwable cause) { 145 if (causeSet) throw new IllegalStateException ("Cause cannot be reset"); 146 if (cause == this) throw new IllegalArgumentException ("Exception cannot be its own cause"); 147 causeSet = true; 148 this.cause = cause; 149 return this; 150 } 151 152 157 public void printStackTrace ( PrintStream s ) 158 { 159 super.printStackTrace ( s ); 160 if (javaVersion < 1.4 && getCause() != null) { 161 s.print( "Caused by: " ); 162 getCause().printStackTrace( s ); 163 } 164 } 165 166 171 public void printStackTrace ( PrintWriter s ) 172 { 173 super.printStackTrace( s ); 174 if (javaVersion < 1.4 && getCause() != null) { 175 s.print( "Caused by: " ); 176 getCause().printStackTrace( s ); 177 } 178 } 179 180 } 181 | Popular Tags |