For all checked exceptions, it becomes mandatory to handle them in your code. Here are 2 ways to do it.
in general, you can either pass exception handling to the caller of the declaration method using the throws . or you can process them there using the try-catch[-finally] .
in your case, you need to either add a throws to the main() method as
public static void main(String []args) throws MalformedURLException {
or you need to surround the url declaration with a try-catch , like here:
try{ URL url = new URL("http://www.google.com/"); //more code goes here }catch(MalformedURLException ex){ //do exception handling here }
Ankit
source share