code: private IOException wrapException(InetSocketAddress addr,
                                           IOException exception) {
      if (exception instanceof ConnectException) {
        //connection refused; include the host:port in the error
        return (ConnectException)new ConnectException(
             "Call to " + addr + " failed on connection exception: " + exception)
                      .initCause(exception);
      } else if (exception instanceof SocketTimeoutException) {
        return (SocketTimeoutException)new SocketTimeoutException(
             "Call to " + addr + " failed on socket timeout exception: "
                        + exception).initCause(exception);
      } else if (exception instanceof NoRouteToHostException) {
        return (NoRouteToHostException)new NoRouteToHostException(
             "Call to " + addr + " failed on NoRouteToHostException exception: "
                        + exception).initCause(exception);
      } else if (exception instanceof PortUnreachableException) {
        return (PortUnreachableException)new PortUnreachableException(
             "Call to " + addr + " failed on PortUnreachableException exception: "
                        + exception).initCause(exception);
      } else if (exception instanceof EOFException) {
          return (EOFException)new EOFException(
               "Call to " + addr + " failed on EOFException exception: "
                          + exception).initCause(exception);
      } else {
        return (IOException)new IOException(
             "Call to " + addr + " failed on local exception: " + exception)
                                   .initCause(exception);
  
      }
    }
docs: Take an IOException and the address we were trying to connect to
  and return an IOException with the input exception as the cause.
  The new exception provides the stack trace of the place where
  the exception is thrown and some extra diagnostics information.
  If the exception is ConnectException or SocketTimeoutException,
  return a new one of the same type; Otherwise return an IOException.
  
  @param addr target address
  @param exception the relevant exception
  @return an exception to throw