If an instance initializer block does not catch a checked exception that can occur during its execution ,then the exception must be declared in the throw clause of every constructor in the class. One the other hand it is also written that constructor can not specify exception in the header. please explain thanks in advance
Hi Payal, Your second statement is wrong (your other hand is incorrect)! To prove it wrong we can just look at the java.io.* package and see many constructors with exceptions specified. For example, let's look at FileInputStream: public FileInputStream(File file) throws FileNotFoundException Regards, Manfred.
Payal, That is correct - If the instance initializer is not catching a Checked Exception the Constructor should take care of it, by declaring in the throws clause. The following code snipplet may be useful
Hope this helps, Sandeep SCJP2,OCSD(Oracle JDeveloper), OCED(Oracle Internet Platform)