This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Compiling it,we got 0,0,0,1,1 Obviously,If we remove Line 17 We got compiling error: unreported exception ColorException; must be caught or declared t o be thrown. Removing 16 and remain Line 17 Compile OK! We got 0,1,0,1,0 We know we should consider inherit relationship of Exception. And I am not surprising the two above-mentioned results. My Question is Since we put LIne 16 before Line17(as you see), why doesn't compiling error whose statement is unreported exception ColorException (like above mentioned)? [ edited to preserve formatting using the [code] and [/code] UBB tags, and to add a little formatting -ds ] [ May 11, 2004: Message edited by: Dirk Schreckmann ]
Since we put LIne 16 before Line17(as you see), why doesn't compiling error whose statement is unreported exception ColorException (like above mentioned)? Since WhiteException is a subclass of ColorException (so, WhiteException is a sub-type of ColorException), a catch block for a ColorException, could also catch a WhiteException. A catch block for a ColorException could catch any exception that is a sub-type of ColorException. The rule is, a catch block, for some type A can, can catch any exception of type A, as well as any exception of a sub-type of A. If you're looking for more resources to better learn the basics of exception handling, I recommend reading