satellite03
IS-IT--Management
Code:
public class ThrowsDemo
{
static void throwMethod()
{
System.out.println("Inside throwMethod.");
}
public static void main(String args[])
{
throwMethod();
}
}
>javac ThrowsDemo.java // compiled ok
>java ThrowsDemo // run ok
Inside throwMethod
but if i change this code like below.........
Code:
public class ThrowsDemo {
static void throwMethod() {
System.out.println("Inside throwMethod.");
throw new IllegalAccessException("demo");
}
public static void main(String args[]) {
try {
throwMethod();
} catch (IllegalAccessException e) {
System.out.println("Caught " + e);
}
}
}
it does not even compile. whats wrong ?
a user throwable exception is created in the throwMethod() so that should be caught by the try-catch block.
why there is compilation error ?