New SocketExceptions in JDK 1.1 (original) (raw)

Home Page

Previously, all network errors in java raised a SocketException, which didn't provide enough information to decipher what went wrong. Was the connection refused by the remote machine (no one listening on that port)? Or was the host unreachable (connect attempt timed out)? JDK 1.1 adds three new classes that provide a finer granularity of reported errors:

The local port is in use, or the requested bind address couldn't be assigned locally.
public class BindException extends SocketException {
...
}

This exception is raised when a connection is refused at the remote host (i.e., no process is listening on that port).
public class ConnectException extends SocketException {
...
}

The connect attempt timed out, or the remote host is otherwise unreachable.
public class NoRouteToHostException extends SocketException {
...
}

Simple Usage Examples: