Originally posted by Jay Kay:
If there was no catch for RuntimeException and only a catch for
Exception, would it still create a compiler error
i.e, If there is no child exception would the parent
exception take care of it's children's exception.
A catch block declared to catch Exception will catch RuntimeExceptions too, since the latter is a subclass of the former.
Yes the parent exception takes care of a child exception, in clear an Exception declared in a catch block will catch all Exception downwards its hierarchy (i.e. all its subclasses)
Originally posted by Jay Kay:
If the parent and child exception catch blocks are present,
if case of a try block is calling the child exception,
would the child exception and parent exception's catch blocks
be called in the order,
i)child exception catch block and ii)parent exception catch block
If the parent and child exception are present the child must come first otherwise there will be a compiler error (catch not reached). Remeber that there is only ONE catch block that will be executed and not every catch block matching the exception thrown !!! This is very important so there is no such thing as the catch block being called in order when child and parent exceptions are thrown...
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for
Java 2 Platform