• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about Constructor signature declared to be throws Exception

 
Ramya Chowdary
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can a construcor declared that it throws Exception,wat is the use of the declaration, the block that uses constructor must be enclosed in "TRY" or not. and wat about the inherited class construtor(the Question is some what ambiguous)

 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you are right. super must be the first statement in a subclass constructor. In the above situation you can just say that the constructor in the subclass also throws the same exception.
 
Satish Kota
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ramya sri:
How can a construcor declared that it throws Exception,wat is the use of the declaration, the block that uses constructor must be enclosed in "TRY" or not. and wat about the inherited class construtor(the Question is some what ambiguous)



super() must be the 1st statement. Hence the only way a subclass constructor handles the exception is by declaring that it throws it, in such case the method which instantiates this class must handle or declare exception. See this example:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic