1 20 21 package org.jivesoftware.smack; 22 23 import org.jivesoftware.smack.packet.XMPPError; 24 25 import java.io.PrintStream ; 26 import java.io.PrintWriter ; 27 28 37 public class XMPPException extends Exception { 38 39 private XMPPError error = null; 40 private Throwable wrappedThrowable = null; 41 42 45 public XMPPException() { 46 super(); 47 } 48 49 54 public XMPPException(String message) { 55 super(message); 56 } 57 58 64 public XMPPException(Throwable wrappedThrowable) { 65 super(); 66 this.wrappedThrowable = wrappedThrowable; 67 } 68 69 75 public XMPPException(XMPPError error) { 76 super(); 77 this.error = error; 78 } 79 80 87 public XMPPException(String message, Throwable wrappedThrowable) { 88 super(message); 89 this.wrappedThrowable = wrappedThrowable; 90 } 91 92 100 public XMPPException(String message, XMPPError error, Throwable wrappedThrowable) { 101 super(message); 102 this.error = error; 103 this.wrappedThrowable = wrappedThrowable; 104 } 105 106 113 public XMPPException(String message, XMPPError error) { 114 super(message); 115 this.error = error; 116 } 117 118 124 public XMPPError getXMPPError() { 125 return error; 126 } 127 128 134 public Throwable getWrappedThrowable() { 135 return wrappedThrowable; 136 } 137 138 public void printStackTrace() { 139 printStackTrace(System.err); 140 } 141 142 public void printStackTrace(PrintStream out) { 143 super.printStackTrace(out); 144 if (wrappedThrowable != null) { 145 out.println("Nested Exception: "); 146 wrappedThrowable.printStackTrace(out); 147 } 148 } 149 150 public void printStackTrace(PrintWriter out) { 151 super.printStackTrace(out); 152 if (wrappedThrowable != null) { 153 out.println("Nested Exception: "); 154 wrappedThrowable.printStackTrace(out); 155 } 156 } 157 158 public String getMessage() { 159 String msg = super.getMessage(); 160 if (msg == null && error != null) { 163 return error.toString(); 164 } 165 return msg; 166 } 167 168 public String toString() { 169 StringBuffer buf = new StringBuffer (); 170 String message = super.getMessage(); 171 if (message != null) { 172 buf.append(message).append(": "); 173 } 174 if (error != null) { 175 buf.append(error); 176 } 177 if (wrappedThrowable != null) { 178 buf.append("\n -- caused by: ").append(wrappedThrowable); 179 } 180 181 return buf.toString(); 182 } 183 } | Popular Tags |