UnknownHostException class in Java

java.net.UnknownHostException

Thrown to indicate that the IP address of a host could not be determined.

Declaration

public class UnknownHostException extends IOException {
    @java.io.Serial
    private static final long serialVersionUID = -4639126076052875403L;

    public UnknownHostException(String message) {
        super(message);
    }

    public UnknownHostException() {
    }
}


Methods

1. UnknownHostException()

java.net.UnknownHostException.UnknownHostException()

Constructs a new UnknownHostException with no detailed message.

Java

package com.UnknownHostException;

import java.net.UnknownHostException;

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

        UnknownHostException unknownHostException = new UnknownHostException();

        System.out.println(unknownHostException);
    }
}

Output:

java.net.UnknownHostException


2. UnknownHostException(String message)

java.net.UnknownHostException.UnknownHostException(String message)

This method takes one argument. This method constructs a new UnknownHostException with the specified detail message.

Parameters: One parameter is required for this method.

message: the detailed message.

Java

package com.UnknownHostException;

import java.net.UnknownHostException;

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

        String message = "exception occured";
        UnknownHostException unknownHostException = new UnknownHostException(message);

        System.out.println(unknownHostException);
    }
}

Output:

java.net.UnknownHostException: exception occured

No comments:

Post a Comment