< prev index next >
src/java.base/share/classes/java/net/DatagramSocket.java
Print this page
@@ -24,10 +24,11 @@
*/
package java.net;
import java.io.IOException;
+import java.io.UncheckedIOException;
import java.nio.channels.DatagramChannel;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
import java.util.Objects;
import java.util.Set;
@@ -496,17 +497,21 @@
*
* @throws SecurityException
* if a security manager has been installed and it does
* not permit access to the given remote address
*
+ * @throws UncheckedIOException
+ * May be thrown by an implementation if connect fails,
+ * for example, if the destination address is non-routable
+ *
* @see #disconnect
*/
public void connect(InetAddress address, int port) {
try {
connectInternal(address, port);
} catch (SocketException se) {
- throw new Error("connect failed", se);
+ throw new UncheckedIOException("connect failed", se);
}
}
/**
* Connects this socket to a remote socket address (IP address + port number).
@@ -543,10 +548,18 @@
/**
* Disconnects the socket. If the socket is closed or not connected,
* then this method has no effect.
*
+ * @apiNote If this method throws an UncheckedIOException, the socket
+ * may be left in an unspecified state. It is strongly recommended that
+ * the socket be closed when disconnect fails.
+ *
+ * @throws UncheckedIOException
+ * May be thrown by an implementation if it fails to dissolve the
+ * association and restore the socket to a consistent state.
+ *
* @see #connect
*/
public void disconnect() {
synchronized (this) {
if (isClosed())
< prev index next >