This is from a jqplus question:
class SomeThrowable extends Throwable { }
class MyThrowable extends SomeThrowable { }
public class TestClass
{
public static void main(
String args[]) throws SomeThrowable
{
try{
m1();
}catch(SomeThrowable e){
System.out.println(e);
throw e;
}finally{
System.out.println("Done");
}
}
public static void m1() throws MyThrowable
{
throw new MyThrowable();
}
}
Ans : This prints Done followed by an Exception.
My Question: Here a checked exception is thrown ultimately in catch which is caught by putting a throws in the main method.
So it is as good as the default handler handling this exception.
So , there is no compile error, agreed but then why during runtime the print statement "Done" is followed by a RunTimeError (when the same has been caught already by the throws in the main method).
Am I losing out something on the concepts?
Also when we say 'throw e' it means we are throwing an object of somethrowable. In that case , are we trying to throw a runtimeexception or checkedException.
Pleas e help me. I have my exam tomorrow.
Thanks padmini