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.
I think IOException is a direct subclass of Exception...and is not a subclass of RuntimeException Why this difference in behaviour in the abv two programs...where i hav only changed the exception type... I may hav not understood some important concept...plz explain
The answer is very simple. The compiler knows that an IOException can never occur because nowhere in the calling code an IOException is thrown. An IOException is a checked exception so it cannot be thrown if not declared. All checked exceptions and runtime exceptions extend from exception. A runtime exception does not have to be placed in the throws clause of a method (constructor, ...). A runtime exception can thus be thrown at any given time by any given code. The compiler will not block the catch(Exception) clause because it is always acceptable(since it is the superclass of all exceptions). You will however never be able to catch an IOException (or other checked exceptions) there because it is never thrown.