MalformedURLException in Java

java.net.MalformedURLException

Thrown to indicate that a malformed URL has occurred. Either no legal protocol could be found in a specification string or the string could not be parsed.

Declaration

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

   
    public MalformedURLException() {
    }

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


Methods

1. MalformedURLException()

java.net.MalformedURLException.MalformedURLException()

This method constructs a MalformedURLException with no detailed message.

Java

package com.MalformedURLException;

import java.net.MalformedURLException;

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

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

Output:

java.net.MalformedURLException


2. MalformedURLException(String msg)

java.net.MalformedURLException.MalformedURLException(String msg)

This method constructs a MalformedURLException with the specified detail message.

Parameters: msg the detail message.

Java

package com.MalformedURLException;

import java.net.MalformedURLException;

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

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

Output:

java.net.MalformedURLException: exception occured

No comments:

Post a Comment