ConnectException in Java

java.net.ConnectException

Signals that an error occurred while attempting to connect a socket to a remote address and port.

Typically, the connection was refused remotely (e.g., no process is listening on the remote address/port).

Declaration

public class ConnectException extends SocketException {
    @java.io.Serial
    private static final long serialVersionUID =
3831404271622369215L;

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

    public ConnectException() {}
}

Methods


1. ConnectException()

java.net.ConnectException.ConnectException()

Construct a new ConnectException with no detailed message.

Approach

Java

package com.ConnectException;

import java.net.ConnectException;

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

        ConnectException connectException =
new ConnectException();

        System.out.println(connectException);
    }
}

Output:

java.net.ConnectException


2. ConnectException(String msg)

java.net.ConnectException.ConnectException(String msg)

Constructs a new ConnectException with the specified detailed message as to why the connect error occurred. A detail message is a String that gives a specific description of this error.

Parameters: msg the detailed message

Approach

Java

package com.ConnectException;

import java.net.ConnectException;

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

        String msg = "message";
        ConnectException connectException =
new ConnectException(msg);

        System.out.println(connectException);
    }
}

Output:

java.net.ConnectException: message


Some other classes/interfaces of java.net

Authenticator: The class Authenticator represents an object that knows how to obtain authentication for a network connection.

BindException: Signals that an error occurred while attempting to bind a socket to a local address and port. 

CacheRequest: Represents channels for storing resources in the ResponseCache.

CacheResponse: Represent channels for retrieving resources from the ResponseCache.

ConnectException: Signals that an error occurred while attempting to connect a socket to a remote address and port.

ContentHandler: The abstract class ContentHandler is the superclass of all classes that read an Object from a URLConnection.

ContentHandlerFactory: This interface defines a factory for content handlers. Implementing this interface should map a MIME type into an instance of ContentHandler.

CookieHandler: A CookieHandler object provides a callback mechanism to hook up an HTTP state management policy implementation into the HTTP protocol handler.

CookieManager: CookieManager provides a concrete implementation of CookieHandler, which separates the storage of cookies from the policy surrounding accepting and rejecting cookies. 

CookiePolicy: CookiePolicy implementations decide which cookies should be accepted and which should be rejected.

CookieStore: A CookieStore object represents storage for cookies. Can store and retrieve cookies.

DatagramPacket: This class represents a datagram packet.

No comments:

Post a Comment