How to Use Throws Clause in Java


This example is to show how to use Throws clause in Java.

Source Code

package com.beginner.examples;

import java.net.MalformedURLException;
import java.net.URL;
 
public class ThrowsExample {
    public static void main(String[] args) throws MalformedURLException{
    	URL url = new URL("https://www.yahoo.com/");
        System.out.println(url);
    }
}

Output:

https://www.yahoo.com/
OK

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments