File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception header in constructor.

 
tanu dua
Ranch Hand
Posts: 145
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanx.

(Edited to get rid of winkie)
[ July 27, 2004: Message edited by: Barry Gaunt ]
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic