Hi,
The following code compiles fine. But when I un-comment the line '//catch (RedException e) {b++;}', there is compiler error 'exception RedException is never thrown in body of corresponding try statement-catch (RedException e) {b++;}.
My doubt is why is there no compiler error with the catch clause 'catch (Exception e) {c++;}' because the try clause is not throwing any kind of Exception at all.
class GreenException extends Exception {}
class BlueException extends Exception {}
class RedException extends GreenException {}
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 {
a++;
}
//catch (RedException e) {b++;}
catch (Exception e) {c++;}
finally {d++;}
System.out.print(a+","+b+","+c+","+d);
}
}
Thanks:
Namita