This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes instance block Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "instance block" Watch "instance block" New topic
Author

instance block

payal sharma
Ranch Hand

Joined: Oct 04, 2000
Posts: 57
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
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
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.
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
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>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: instance block
 
Similar Threads
how to throw exception from class level static block?
exception handling in initializers
Instance Initializer
Instance blocks.
exception in instance block