File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception header in constructor. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception header in constructor." Watch "Exception header in constructor." New topic

Exception header in constructor.

tanu dua
Ranch Hand

Joined: Apr 05, 2004
Posts: 145
Hi all !

Can anyone please sort out my problem :

Problem : In Khaled book the syntax of constructor is written as follows :
<constructor header> (<parameter list> )
<constructor body>

And one restriction is given that : "Constructors cant specify exceptions in the header"

I revealed from this statement that you cant use throws caluse in constructor till i have attempted to compile the follwing piece of code which compiles fine

class exp
exp() throws Exception {}

So please explain me what the above statement is conveying.


(Edited to get rid of winkie)
[ July 27, 2004: Message edited by: Barry Gaunt ]
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Although my mock exam web site contains a mock exam set that is organized based on the chapters of Khalid's book, I have never actually seen his book. Instead, my primary source of information for my mock exams was the Java Language Specification, so I can direct you to the chapter of the JLS that covers constructors.

The term "constructor header" appears to be something that Khalid defined to simplify the topic, so I can't offer any more information on that term beyond what appears in his book. All I can say is that a constructor declaration can include a "throws clause".

Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="" target="_blank" rel="nofollow">Try my mock exam.</a>
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
In the current 2nd Edition (for SCJP 1.4) of the book it has (p 117 section 4.4):

I cannot see any mention of a restriction regarding exceptions.
[ July 27, 2004: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
I agree. Here's the link:
subject: Exception header in constructor.
It's not a secret anymore!