Hi Guys
chk this
class RedException extends Exception {}
class BlueException extends Exception {}
class White {
void m1() throws RedException {throw new RedException();}
public static void main (
String[] args) {
White white = new White();
int a,b,c,d;
a = b = c = d = 0;
try {white.m1();a++;}
catch (RedException e) {b++;}
catch (BlueException e) {c++;}
finally {d++;}
System.out.print(a+","+b+","+c+","+d);
}
}
What is the result of attempting to compile and run the program?
Dans answer is
A compile-time error is generated because the second catch clause attempts to catch an exception that is never thrown in the try block.
My doubt is whether its a neccessity to throw only those exceptions that are stated to be thrown
Best
Mandeep