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
Joined: Jan 09, 2001
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.
Joined: Apr 02, 2001
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)
<b>Sandeep</b> <br /> <br /><b>Sun Certified Programmer for Java 2 Platform</b><br /> <br /><b>Oracle Certified Solution Developer - JDeveloper</b><br /><b>-- Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java </b><br /><b>-- Object-Oriented Analysis and Design with UML</b><br /> <br /><b>Oracle Certified Enterprise Developer - Oracle Internet Platform</b><br /><b>-- Enterprise Connectivity with J2EE </b><br /><b>-- Enterprise Development on the Oracle Internet Platform </b>