1 25 26 package org.jresearch.gossip.exception; 27 28 import java.io.PrintStream ; 29 import java.io.PrintWriter ; 30 import java.io.StringWriter ; 31 32 39 public class JGossipException extends Exception { 40 41 44 private static final long serialVersionUID = -2799181321033636504L; 45 46 47 private Exception nestedException; 48 49 52 protected JGossipException() { 53 super(); 54 nestedException = null; 55 } 56 57 63 protected JGossipException(String msg) { 64 super(msg); 65 nestedException = null; 66 } 67 68 74 protected JGossipException(Exception cause) { 75 super(); 76 nestedException = cause; 77 } 78 79 86 protected JGossipException(String msg, Exception cause) { 87 super(msg); 88 nestedException = cause; 89 } 90 91 96 public Exception getNestedException() { 97 return nestedException; 98 } 99 100 105 public String getMessage() { 106 107 String msg = super.getMessage(); 108 Exception ex = getNestedException(); 109 110 if (ex != null) { 111 String s = ex.getMessage(); 112 113 if (s != null) { 114 if (msg == null) 115 msg = ""; 116 else 117 msg += "\n"; 118 msg += "CAUSE: " + s; 119 } 120 } 121 return msg; 122 } 123 124 129 public String getTrace() { 130 131 StringWriter strwrt = new StringWriter (); 132 133 super.printStackTrace(new PrintWriter (strwrt)); 134 return strwrt.toString(); 135 } 136 137 142 public void printStackTrace(PrintStream out) { 143 144 Exception ex = getNestedException(); 145 146 if (ex != null) { 147 ex.printStackTrace(out); 148 out.println("WRAPPING EXCEPTION:"); 149 } 150 super.printStackTrace(out); 151 } 152 153 158 public void printStackTrace(PrintWriter out) { 159 160 Exception ex = getNestedException(); 161 162 if (ex != null) { 163 ex.printStackTrace(out); 164 out.println("WRAPPING EXCEPTION:"); 165 } 166 super.printStackTrace(out); 167 } 168 169 172 public void printStackTrace() { 173 printStackTrace(System.err); 174 } 175 } 176 | Popular Tags |