Skip to main content

If i write things like this :

 public static void main(String[] args) {   try {   } catch (MalformedURLException e) { e.printStackTrace()}; e.printStackTrace()  }; } 

Java compiler shows compilation error at catch clause of MalformedURLExceptionMalformedURLException. If i insert line URL url = new URL("HI");URL url = new URL("HI"); in try block , complaining stops. I thought java must be binding these checked exceptions with package. Then i tried another class of java.net package by inserting " CookieManager manager = new CookieManager(); CookieManager manager = new CookieManager(); " only in try block. Compilation error again starts.

So how does JVM bind these checked exceptions with java classes for compilation time errors like this?

If i write things like this :

 public static void main(String[] args) {   try {   } catch (MalformedURLException e) { e.printStackTrace()}; } 

Java compiler shows compilation error at catch clause of MalformedURLException. If i insert line URL url = new URL("HI"); in try block , complaining stops. I thought java must be binding these checked exceptions with package. Then i tried another class of java.net package by inserting " CookieManager manager = new CookieManager(); " only in try block. Compilation error again starts.

So how does JVM bind these checked exceptions with java classes for compilation time errors like this?

If i write things like this :

public static void main(String[] args) { try { } catch (MalformedURLException e) { e.printStackTrace()  }; } 

Java compiler shows compilation error at catch clause of MalformedURLException. If i insert line URL url = new URL("HI"); in try block , complaining stops. I thought java must be binding these checked exceptions with package. Then i tried another class of java.net package by inserting " CookieManager manager = new CookieManager(); " only in try block. Compilation error again starts.

So how does JVM bind these checked exceptions with java classes for compilation time errors like this?

Source Link
mohit
  • 1.1k
  • 1
  • 9
  • 18

How does java detects Checked Exceptions?

If i write things like this :

 public static void main(String[] args) { try { } catch (MalformedURLException e) { e.printStackTrace()}; } 

Java compiler shows compilation error at catch clause of MalformedURLException. If i insert line URL url = new URL("HI"); in try block , complaining stops. I thought java must be binding these checked exceptions with package. Then i tried another class of java.net package by inserting " CookieManager manager = new CookieManager(); " only in try block. Compilation error again starts.

So how does JVM bind these checked exceptions with java classes for compilation time errors like this?