00001 package cedar.hepdata.util;
00002
00003 import java.io.PrintStream;
00004 import java.io.PrintWriter;
00005
00006
00013 public class HDException extends Exception {
00014 private String data = "";
00015 private Exception originalException;
00016
00022 public HDException(Exception originalException) {
00023 super(originalException.getMessage());
00024 this.originalException = originalException;
00025 }
00026
00033 public HDException(Exception originalException, String msg) {
00034 super(msg + " " + originalException.getMessage());
00035 this.originalException = originalException;
00036 }
00037
00044 public HDException(String message, String data) {
00045 super(message);
00046 this.data = data;
00047 }
00048
00054 public HDException(String message) {
00055 super(message);
00056 }
00057
00061 public HDException() {
00062 super("Generic HepData exception");
00063 }
00064
00071 public void printStackTrace(PrintWriter printWriter) {
00072 if (originalException != null) {
00073 originalException.printStackTrace(printWriter);
00074 } else {
00075 super.printStackTrace(printWriter);
00076 }
00077 }
00078
00085 public void printStackTrace(PrintStream printStream) {
00086 if (originalException != null) {
00087 originalException.printStackTrace(printStream);
00088 } else {
00089 super.printStackTrace(printStream);
00090 }
00091 }
00092
00099 public String getMessage() {
00100 StringBuffer b = new StringBuffer();
00101
00102
00103
00104 b.append(super.getMessage());
00105
00106
00107
00108
00109
00110
00111 if (data != "") {
00112 b.append(":DATA:");
00113 b.append(data);
00114 }
00115
00116 return b.toString();
00117 }
00118
00124 public Exception getOriginalException() {
00125 return originalException;
00126 }
00127 }