SMACK-465: XMPPException using Java's wrapped Throwable

This commit is contained in:
Georg Lukas 2013-11-11 09:33:31 +01:00
parent 602a8fc812
commit fea2db2be7
1 changed files with 8 additions and 34 deletions

View File

@ -20,9 +20,6 @@ package org.jivesoftware.smack;
import org.jivesoftware.smack.packet.StreamError; import org.jivesoftware.smack.packet.StreamError;
import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smack.packet.XMPPError;
import java.io.PrintStream;
import java.io.PrintWriter;
/** /**
* A generic exception that is thrown when an error occurs performing an * A generic exception that is thrown when an error occurs performing an
* XMPP operation. XMPP servers can respond to error conditions with an error code * XMPP operation. XMPP servers can respond to error conditions with an error code
@ -42,7 +39,6 @@ public class XMPPException extends Exception {
private StreamError streamError = null; private StreamError streamError = null;
private XMPPError error = null; private XMPPError error = null;
private Throwable wrappedThrowable = null;
private SmackError smackError = null; private SmackError smackError = null;
/** /**
@ -78,8 +74,7 @@ public class XMPPException extends Exception {
* @param wrappedThrowable the root cause of the exception. * @param wrappedThrowable the root cause of the exception.
*/ */
public XMPPException(Throwable wrappedThrowable) { public XMPPException(Throwable wrappedThrowable) {
super(); super(wrappedThrowable);
this.wrappedThrowable = wrappedThrowable;
} }
/** /**
@ -113,8 +108,7 @@ public class XMPPException extends Exception {
* @param wrappedThrowable the root cause of the exception. * @param wrappedThrowable the root cause of the exception.
*/ */
public XMPPException(String message, Throwable wrappedThrowable) { public XMPPException(String message, Throwable wrappedThrowable) {
super(message); super(message, wrappedThrowable);
this.wrappedThrowable = wrappedThrowable;
} }
/** /**
@ -126,9 +120,8 @@ public class XMPPException extends Exception {
* @param wrappedThrowable the root cause of the exception. * @param wrappedThrowable the root cause of the exception.
*/ */
public XMPPException(String message, XMPPError error, Throwable wrappedThrowable) { public XMPPException(String message, XMPPError error, Throwable wrappedThrowable) {
super(message); super(message, wrappedThrowable);
this.error = error; this.error = error;
this.wrappedThrowable = wrappedThrowable;
} }
/** /**
@ -176,32 +169,13 @@ public class XMPPException extends Exception {
/** /**
* Returns the Throwable asscociated with this exception, or <tt>null</tt> if there * Returns the Throwable asscociated with this exception, or <tt>null</tt> if there
* isn't one. * isn't one. @deprecated, use Exception.getCause() instead.
* *
* @return the Throwable asscociated with this exception. * @return the Throwable asscociated with this exception.
*/ */
@Deprecated
public Throwable getWrappedThrowable() { public Throwable getWrappedThrowable() {
return wrappedThrowable; return getCause();
}
public void printStackTrace() {
printStackTrace(System.err);
}
public void printStackTrace(PrintStream out) {
super.printStackTrace(out);
if (wrappedThrowable != null) {
out.println("Nested Exception: ");
wrappedThrowable.printStackTrace(out);
}
}
public void printStackTrace(PrintWriter out) {
super.printStackTrace(out);
if (wrappedThrowable != null) {
out.println("Nested Exception: ");
wrappedThrowable.printStackTrace(out);
}
} }
public String getMessage() { public String getMessage() {
@ -229,8 +203,8 @@ public class XMPPException extends Exception {
if (streamError != null) { if (streamError != null) {
buf.append(streamError); buf.append(streamError);
} }
if (wrappedThrowable != null) { if (getCause() != null) {
buf.append("\n -- caused by: ").append(wrappedThrowable); buf.append("\n -- caused by: ").append(getCause());
} }
return buf.toString(); return buf.toString();