This example is to show how to handle exceptions in Java.
Source Code
package com.beginner.examples;
import java.net.MalformedURLException;
import java.net.URL;
public class ExceptionHandlingExample {
public static void main(String[] args){
try
{
URL url = new URL("https://www.yahoo.com/");
System.out.println(url);
}
catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Output:
https://www.yahoo.com/
References
Imported packages in Java documentation: