From fea2db2be7bc265882031e3de3dbf1b1fd12e8c0 Mon Sep 17 00:00:00 2001 From: Georg Lukas Date: Mon, 11 Nov 2013 09:33:31 +0100 Subject: [PATCH] SMACK-465: XMPPException using Java's wrapped Throwable --- .../org/jivesoftware/smack/XMPPException.java | 42 ++++--------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/core/src/main/java/org/jivesoftware/smack/XMPPException.java b/core/src/main/java/org/jivesoftware/smack/XMPPException.java index 11718264d..84fd546a5 100644 --- a/core/src/main/java/org/jivesoftware/smack/XMPPException.java +++ b/core/src/main/java/org/jivesoftware/smack/XMPPException.java @@ -20,9 +20,6 @@ package org.jivesoftware.smack; import org.jivesoftware.smack.packet.StreamError; 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 * 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 XMPPError error = null; - private Throwable wrappedThrowable = null; private SmackError smackError = null; /** @@ -78,8 +74,7 @@ public class XMPPException extends Exception { * @param wrappedThrowable the root cause of the exception. */ public XMPPException(Throwable wrappedThrowable) { - super(); - this.wrappedThrowable = wrappedThrowable; + super(wrappedThrowable); } /** @@ -113,8 +108,7 @@ public class XMPPException extends Exception { * @param wrappedThrowable the root cause of the exception. */ public XMPPException(String message, Throwable wrappedThrowable) { - super(message); - this.wrappedThrowable = wrappedThrowable; + super(message, wrappedThrowable); } /** @@ -126,9 +120,8 @@ public class XMPPException extends Exception { * @param wrappedThrowable the root cause of the exception. */ public XMPPException(String message, XMPPError error, Throwable wrappedThrowable) { - super(message); + super(message, wrappedThrowable); this.error = error; - this.wrappedThrowable = wrappedThrowable; } /** @@ -176,32 +169,13 @@ public class XMPPException extends Exception { /** * Returns the Throwable asscociated with this exception, or null if there - * isn't one. + * isn't one. @deprecated, use Exception.getCause() instead. * * @return the Throwable asscociated with this exception. */ + @Deprecated public Throwable getWrappedThrowable() { - return wrappedThrowable; - } - - 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); - } + return getCause(); } public String getMessage() { @@ -229,8 +203,8 @@ public class XMPPException extends Exception { if (streamError != null) { buf.append(streamError); } - if (wrappedThrowable != null) { - buf.append("\n -- caused by: ").append(wrappedThrowable); + if (getCause() != null) { + buf.append("\n -- caused by: ").append(getCause()); } return buf.toString();