hi friends
i am confused with strange behaviour of this program.
import java.lang.*;
public class ExceptionTest
{
public static void main(String ... args)
{
ExceptionTest obj = new ExceptionTest();
obj.method1();
}
void method1()
{
throw new Exception(); //line1
//throw new Throwable(); //line2
}
}
as we know Throwable is the superclass of Exception. in the above code it gives error on compiling as
ExceptionTest.java:21: incompatible types
found : Exception
required: java.lang.Throwable
throw new Exception();
^
1 error
but if we uncomment line 2, and comment line 1 then error will be
ExceptionTest.java:22: unreported exception java.lang.Throwable; must be caught
or declared to be thrown
throw new Throwable();
^
1 error
why does it provides a eoor saying incompatible types on throwing new exception()?
i expected following error in first case
ExceptionTest.java:21: unreported exception java.lang.Exception; must be caught
or declared to be thrown
throw new Exception();
^
1 error
whats happening here?

