diff --git a/source/org/jivesoftware/smack/SSLXMPPConnection.java b/source/org/jivesoftware/smack/SSLXMPPConnection.java
index b8c8aa930..76e540e23 100644
--- a/source/org/jivesoftware/smack/SSLXMPPConnection.java
+++ b/source/org/jivesoftware/smack/SSLXMPPConnection.java
@@ -66,6 +66,8 @@ import java.security.cert.X509Certificate;
import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateNotYetValidException;
+import org.jivesoftware.smack.packet.XMPPError;
+
/**
* Creates an SSL connection to a XMPP server.
@@ -79,7 +81,11 @@ public class SSLXMPPConnection extends XMPPConnection {
* SSL port (5223).
*
* @param host the XMPP host.
- * @throws XMPPException if an error occurs making the connection.
+ * @throws XMPPException if an error occurs while trying to establish the connection.
+ * Two possible errors can occur which will be wrapped by an XMPPException --
+ * UnknownHostException (XMPP error code 504), and IOException (XMPP error code
+ * 502). The error codes and wrapped exceptions can be used to present more
+ * appropiate error messages to end-users.
*/
public SSLXMPPConnection(String host) throws XMPPException {
this(host, 5223);
@@ -90,7 +96,11 @@ public class SSLXMPPConnection extends XMPPConnection {
*
* @param host the XMPP host.
* @param port the port to use for the connection (default XMPP SSL port is 5223).
- * @throws XMPPException if an error occurs making the connection.
+ * @throws XMPPException if an error occurs while trying to establish the connection.
+ * Two possible errors can occur which will be wrapped by an XMPPException --
+ * UnknownHostException (XMPP error code 504), and IOException (XMPP error code
+ * 502). The error codes and wrapped exceptions can be used to present more
+ * appropiate error messages to end-users.
*/
public SSLXMPPConnection(String host, int port) throws XMPPException {
this.host = host;
@@ -100,10 +110,12 @@ public class SSLXMPPConnection extends XMPPConnection {
this.socket = sslFactory.createSocket(host, port);
}
catch (UnknownHostException uhe) {
- throw new XMPPException("Could not connect to " + host + ":" + port + ".", uhe);
+ throw new XMPPException("Could not connect to " + host + ":" + port + ".",
+ new XMPPError(504), uhe);
}
catch (IOException ioe) {
- throw new XMPPException("XMPPError connecting to " + host + ":" + port + ".", ioe);
+ throw new XMPPException("XMPPError connecting to " + host + ":" + port + ".",
+ new XMPPError(502), ioe);
}
super.init();
}
diff --git a/source/org/jivesoftware/smack/XMPPConnection.java b/source/org/jivesoftware/smack/XMPPConnection.java
index f467dadc2..19009a63d 100644
--- a/source/org/jivesoftware/smack/XMPPConnection.java
+++ b/source/org/jivesoftware/smack/XMPPConnection.java
@@ -138,7 +138,11 @@ public class XMPPConnection {
* be used.
*
* @param host the name of the XMPP server to connect to; e.g. jivesoftware.com.
- * @throws XMPPException if an error occurs while trying to establish a connection.
+ * @throws XMPPException if an error occurs while trying to establish the connection.
+ * Two possible errors can occur which will be wrapped by an XMPPException --
+ * UnknownHostException (XMPP error code 504), and IOException (XMPP error code
+ * 502). The error codes and wrapped exceptions can be used to present more
+ * appropiate error messages to end-users.
*/
public XMPPConnection(String host) throws XMPPException {
this(host, 5222);
@@ -149,7 +153,11 @@ public class XMPPConnection {
*
* @param host the name of the XMPP server to connect to; e.g. jivesoftware.com.
* @param port the port on the server that should be used; e.g. 5222.
- * @throws XMPPException if an error occurs while trying to establish a connection.
+ * @throws XMPPException if an error occurs while trying to establish the connection.
+ * Two possible errors can occur which will be wrapped by an XMPPException --
+ * UnknownHostException (XMPP error code 504), and IOException (XMPP error code
+ * 502). The error codes and wrapped exceptions can be used to present more
+ * appropiate error messages to end-users.
*/
public XMPPConnection(String host, int port) throws XMPPException {
this.host = host;
@@ -158,10 +166,12 @@ public class XMPPConnection {
this.socket = new Socket(host, port);
}
catch (UnknownHostException uhe) {
- throw new XMPPException("Could not connect to " + host + ":" + port + ".", uhe);
+ throw new XMPPException("Could not connect to " + host + ":" + port + ".",
+ new XMPPError(502), uhe);
}
catch (IOException ioe) {
- throw new XMPPException("XMPPError connecting to " + host + ":" + port + ".", ioe);
+ throw new XMPPException("XMPPError connecting to " + host + ":" + port + ".",
+ new XMPPError(502), ioe);
}
init();
}
@@ -601,7 +611,8 @@ public class XMPPConnection {
writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF-8"));
}
catch (IOException ioe) {
- throw new XMPPException("XMPPError establishing connection with server.", ioe);
+ throw new XMPPException("XMPPError establishing connection with server.",
+ new XMPPError(502), ioe);
}
// If debugging is enabled, we open a window and write out all network traffic.
diff --git a/source/org/jivesoftware/smack/XMPPException.java b/source/org/jivesoftware/smack/XMPPException.java
index 70878c243..7f767ab49 100644
--- a/source/org/jivesoftware/smack/XMPPException.java
+++ b/source/org/jivesoftware/smack/XMPPException.java
@@ -121,6 +121,20 @@ public class XMPPException extends Exception {
this.wrappedThrowable = wrappedThrowable;
}
+ /**
+ * Creates a new XMPPException with a description of the exception, an XMPPError,
+ * and the Throwable that was the root cause of the exception.
+ *
+ * @param message a description of the exception.
+ * @param error the root cause of the exception.
+ * @param wrappedThrowable the root cause of the exception.
+ */
+ public XMPPException(String message, XMPPError error, Throwable wrappedThrowable) {
+ super(message);
+ this.error = error;
+ this.wrappedThrowable = wrappedThrowable;
+ }
+
/**
* Creates a new XMPPException with a description of the exception and the
* XMPPException that was the root cause of the exception.