Hello All,
I have one query regarding following example,
1:import java.io.FileNotFoundException;
2:import java.io.IOException;
3:class SubException extends Exception { }
4:class SubSubException extends SubException { }
5:public class CC { void doStuff() throws SubException { } }
6:class CC2 extends CC { void doStuff() throws SubSubException { } }
7:class CC3 extends CC { void doStuff() throws Exception { } }
8:class CC4 extends CC { void doStuff(int x) throws Exception { } }
9:class CC5 extends CC { void doStuff() { } }
10:class CC6 extends CC { void doStuff() throws FileNotFoundException { } }
here if we compile above example,there will be compilation error at line 7 & 10.
according to the rule
"An overriding method cannot throw a broader exception than the method it's
overriding."
For line number 8 the exception thrown is "Exception" it self,which is not broader than class SubException,as class SubException already extending the class Exception.
can anyone explain what is the reason for compilation error at line 7 & 10.
Thanks in advance,
Ravi