what i dont understand is why option B is incorrect? the quesion states "method aMethod() throws BaseException, SubException and RuntimeException ", then why cant we throw both BaseException and RunTimeException together from myMethod... the way we handle these exceptions is beyond the scope of this question right?can't myMethod choose to throw these exceptions? i know i'm missing something here.. can anyone explain???

RuntimeException are unchecked kind of Exceptions.This kind of exception is managed by JVM itself,Compiler doesnot put any obligation to throw or handle these kind of exception,However All exceptions which are derived from non - RuntimeException class are Checked Exceptions,For this we have to handle and throw these exceptions. To get more on this refer to K&B Chap-5.

This is because inheritance hierarchy. BaseException is the super class of RuntimeException and as per the inheritance rule super class can refer to any of the subclass without casting.

So here "BaseException" or "Exception" can handle any other exceptions and there is no need to define "RuntimeException" to create duplicacy. Here "RuntimeException" is nothing but the "BaseException" for compiler.

Radha Kamesh
Ranch Hand

Joined: May 19, 2007
Posts: 33

posted Sep 04, 2007 08:02:00

0

sorry friends, the diagram for the exception hierarchy i had posted came out wrongly.. i have now out it in a code block for the structure to be retained......

according to the diagram, now both BaseException and RuntimeException derive directly from Exception...

i know that Runtime exception need not be declared... but is it wrong to do so in this case?