Hi Vishy,
In the 1st example, since there is no inheriance relationship between RedException and WhiteException and m1() does NOT throw BlueException, thus, if you catch the BlueException in a try-catch-block, the compile sure complain that, BlueException is never thrown.
In the 2nd example, on the other hand, there DOES inheriance relationship beteweeh ColorException and WhiteException. The relationship is WhiteException extends ColorException.
In method m1(), it declares to throw ColorException. According to the
Java rule, if a method that declare to throw Exception E, if E (or exception classes that extend E [subclasses of E]) is encountered, it will be thrown without any problems, and thus, the try-catch-block of m1() has no problem.
Does this make sense?
Nick.
SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)