Hi all,
In the code given below, If I compile I get the
C:\Java\bin>javac Test.java
Test.java:24: Exception MyException must be caught, or it must be declared in the throws clause of this method.
tc.m1();
^
1 error
As the error says the "Exception MyException must be 'caught' or declared in throws clause", I have the catch in the try block to catch the exception, Why does it still gives an error. ?
But if I code the throws clause in the main method it does'nt give the Error.
Can anyone explain. ?
class MyException extends Exception {}
public class
Test {
public static void main(
String[ ] args)
{
Test tc = new Test();
try
{
tc.m1();
}
catch (MyException e)
{
tc.m1();
}
finally
{
tc.m2();
}
}
public void m1() throws MyException
{
throw new MyException();
}
public void m2() throws RuntimeException
{
throw new NullPointerException();
}
}
Thx in advance.
Aruna