That is quite incorrect. You cannot declare a new Exception without violating the Liskov substitution Principle. If the superclass' method is feasible without Exceptions then the subclass' method must be feasible without Exceptions.Tarun Oohri wrote: . . . Que 1 Why is it that, If the superclass method does not declare an exception, subclass overridden method cannot declare the checked exception but it can declare unchecked exception ?
It is actually the same reason. If you catch a particular kind of Exception, you catch its subclasses. Not its superclass.Que2 Why is it that, If the superclass method declares an exception, subclass overridden method can declare same, subclass exception or no exception but cannot declare parent exception ?
Thanks!!!
You cannot declare a new Exception without violating the Liskov substitution Principle. If the superclass' method is feasible without Exceptions then the subclass' method must be feasible without Exceptions.
The unchecked exception classes (ยง11.1.1) are exempted from compile-time checking.
No. There is no such thing as a compile‑time Exception. The name RuntimeException is confusing. It does not mean an Exception which occurs at runtime, but an Exception which occurs (entirely) inside the runtime. Other Exceptions occur partially outwith the runtime. At least that is the theory.Tarun Oohri wrote: . . .
Is it correct to say :
Checked Exceptions are compile time exceptions such as Exception , IOException , SQLException etc
UnChecked Exceptions are Run time Exceptions such as RunTimeException , Error etc
Campbell Ritchie wrote:The name RuntimeException is confusing. It does not mean an Exception which occurs at runtime, but an Exception which occurs (entirely) inside the runtime. Other Exceptions occur partially outwith the runtime. At least that is the theory.
Campbell Ritchie wrote:If you get a runtime exception (eg NullPointerException, divide by zero) you will have to go back to the code and ensure the null is replaced by a real reference or the 0 by a different number. There are very few runtime exceptions which can be sorted out without altering the code. So there is no point in catching them.
Campbell Ritchie wrote:At least Mike and I agreed about RuntimeException being a bad name
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here