Suppose We have a Interface in which there are methods that throws a Exception .Now in the implementation of that method do we have to throw the same exception or can we throw the subclass of that exception or vice-versa.
Thanks in advance..!
(Ed topic: No need to shout!) [ August 30, 2005: Message edited by: Barry Gaunt ]
Thanks and Regards,<br />Nilesh<br />SCJP 1.4, SCWCD 1.4
If u declared a particular Exception for the method in the Interface it is not compulsory in the first place to throw any Exception in the implementation class.
If u want to throw exception for the method in the implementation class as u said it should be a subclass of the exception defined in the Interface
my observation showed me that if throw ArithmeticException in the Interface in the implementation class i throwed for the same method FileNotFoundException so with this i understood that it is not at all mandatory to throw the same exception in the implementation class.
another observation is if i throwed "Exception" in the implementation class as it was superclass it gave compile time exception.
Satish SN<br />SCJP 1.4 & SCWCD 1.4
Joined: Aug 02, 2005
Thanks afor your reply..!But when Exceptions with respect to Inheritance,overiding..! We cannot throw the subclass of the exception in the overiding method or we cant throw more genralized for of exception in the overiding method ..!We have to throw exactly or more specific exception..!
Well then as per your previous mail y is it not so in Case of Interfaces..!