Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query

 
ashish mittal
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all ,
just have a little doubt . The khalid book says that ctors cannot display exceptions in header , whereas in more than one study notes , its said that ctors can throw any exception ???
 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ofcourse ctrs can throw any exception....
------------------
azaman
 
Muhammad Farooq
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Construtor can throw an exception, but cannot declare the exception in their header with the clause "throws".
HTH
--Farooq
 
Gurpreet Sachdeva
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ashish,
Its mistake in the book, please see its errata pages for more details.You can view it at: http://www.ii.uib.no/~khalid/pgjc/jcbook/errata.html

Gurpreet Sachdeva
For mock exams and other useful pages(including topics like bitshift operator, garbage collection,inner classes,etc) please visit: http://www.go4java.20m.com
[This message has been edited by Gurpreet Sachdeva (edited August 18, 2001).]
 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Construtor can throw an exception, but cannot declare the exception in their header with the clause "throws

Farooq,
I disagree with u in this respect. Constructors can throw any exception and also can declara in its header the unhandled exceptions it throws. See the following code.


------------------
azaman
 
Muhammad Farooq
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are rite Aazman, Thanks for pointing out. Is it the same for checked or unchecked exceptions.
--Farooq
 
ashok khetan
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i am agree with ashik, it's a mistake in khalid book(page 101). if the constructor doesn't declare any checked exception in the header using throws clause then it would produce an error.
ashok.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic