NoRouteToHostException class in Java

java.net.NoRouteToHostException

Signals that an error occurred while attempting to connect a socket to a remote address and port. Typically, the remote host cannot be reached because of an intervening firewall, or if an intermediate router is down.

Declaration

public class NoRouteToHostException extends SocketException {
    @java.io.Serial
    private static final long serialVersionUID = -1897550894873493790L;

    public NoRouteToHostException(String msg) {
        super(msg);
    }

    public NoRouteToHostException() {
    }
}


Methods

1. NoRouteToHostException()

java.net.NoRouteToHostException.NoRouteToHostException()

Construct a new NoRouteToHostException with no detailed message.

Java

package com.NoRouteToHostException;

import java.net.NoRouteToHostException;

public class NoRouteToHostException1 {
    public static void main(String[] args) {

        NoRouteToHostException exception =
new NoRouteToHostException();
        System.out.println(exception);
    }
}

Output:

java.net.NoRouteToHostException


2. NoRouteToHostException(String msg)

java.net.NoRouteToHostException.NoRouteToHostException(String msg)

Constructs a new NoRouteToHostException with the specified detail message as to why the remote host cannot be reached.A detail message is a String that gives a specific description of this error.

Parameters: One parameter is required for this method.

msg: the detailed message

Java

package com.NoRouteToHostException;

import java.net.NoRouteToHostException;

public class NoRouteToHostException2 {
    public static void main(String[] args) {

        String msg = "exception occured";
        NoRouteToHostException exception =
new NoRouteToHostException(msg);
        System.out.println(exception);
    }
}

Output:

java.net.NoRouteToHostException: exception occured

No comments:

Post a Comment