m2() does not have any code, nor it is inherited. And nothing is inherited from it. What is the purpose of throws clause. Should it not give compile error? Thanks Barkat
A method can declare a checked exception in its throws clause (assuming this does not collide with an overriden method's throws clause) even if the implementation doesn't really throw a checked exception. For example:
If you omit the throws clause in m2() there will be the following error
That is you need to declare, but not really throw, those checked exceptions that are caught. If the catch wasn't present, notice that the compiler won't complain about declaring an exception that is not thrown. In this way a method is able to declare the type or supertypes of the exceptions that possibly overriding methods are allowed to throw.