This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes about Constructor signature declared to be throws Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "about Constructor signature declared to be throws Exception" Watch "about Constructor signature declared to be throws Exception" New topic
Author

about Constructor signature declared to be throws Exception

Pratap koritala
Ranch Hand

Joined: Sep 27, 2006
Posts: 251
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

Joined: Sep 26, 2006
Posts: 8795

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.


SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
Satish Kota
Ranch Hand

Joined: Feb 08, 2006
Posts: 88
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:



SCJP 5.0 77%
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: about Constructor signature declared to be throws Exception
 
Similar Threads
throwing Exception
Exception never thrown....
Exception handling for overridding constractor
catching exception from parent's constructor
try catch in constructor