SocketTimeoutException class in Java

java.net.SocketTimeoutException

Signals that a timeout has occurred on a socket read or accept.

Declaration

public class SocketTimeoutException extends java.io.InterruptedIOException {
    @java.io.Serial
    private static final long serialVersionUID = -8846654841826352300L;

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

    public SocketTimeoutException() {}
}


Methods

1. SocketTimeoutException()

java.net.SocketTimeoutException.SocketTimeoutException()

Construct a new SocketTimeoutException with no detailed message.

Java

package com.SocketTimeoutException;

import java.net.SocketTimeoutException;

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

        SocketTimeoutException socketTimeoutException = new SocketTimeoutException();

        System.out.println(socketTimeoutException);
    }
}

Output:

java.net.SocketTimeoutException


2. SocketTimeoutException(String msg)

java.net.SocketTimeoutException.SocketTimeoutException(String msg)

This method takes one argument. This method constructs a new SocketTimeoutException with a detailed message.

Parameters: One parameter is required for this method.

msg: the detailed message

Java

package com.SocketTimeoutException;

import java.net.SocketTimeoutException;

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

        String msg = "exception occured";
        SocketTimeoutException socketTimeoutException = new SocketTimeoutException(msg);

        System.out.println(socketTimeoutException);
    }
}

Output:

java.net.SocketTimeoutException: exception occured

No comments:

Post a Comment