UnknownServiceException class in Java

java.net.UnknownServiceException

Thrown to indicate that an unknown service exception has occurred. Either the MIME type returned by a URL connection does not make sense, or the application is attempting to write to a read-only URL connection.

Declaration

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

   
    public UnknownServiceException() {
    }

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


Methods

1. UnknownServiceException()

java.net.UnknownServiceException.UnknownServiceException()

Constructs a new UnknownServiceException with no detail message.

Java

package com.UnknownServiceException;

import java.net.UnknownServiceException;

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

        UnknownServiceException unknownServiceException = new UnknownServiceException();

        System.out.println(unknownServiceException);
    }
}

Output:

java.net.UnknownServiceException


2. UnknownServiceException(String msg)

java.net.UnknownServiceException.UnknownServiceException(String msg)

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

Parameters: One parameter is required for this method.

msg: the detail message.

Java

package com.UnknownServiceException;

import java.net.UnknownServiceException;

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

        String msg = "exception occured";
        UnknownServiceException unknownServiceException = new UnknownServiceException(msg);

        System.out.println(unknownServiceException);
    }
}

Output:

java.net.UnknownServiceException: exception occured

No comments:

Post a Comment