This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Instance Initializer, throw statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Instance Initializer, throw statement" Watch "Instance Initializer, throw statement" New topic
Author

Instance Initializer, throw statement

Manish Kumar
Ranch Hand

Joined: Apr 15, 2002
Posts: 53
The JLS section 8.6 :

An instance initializer of a named class may not throw a checked exception unless
that exception or one of its superclasses is explicitly declared in the throws
clause of each constructor of its class and the class has at least one
explicitly declared constructor. An instance initializer in an anonymous
class (�15.9.5) can throw any exceptions.


According to the statement the following code should compile, but it is not compiling.

Pease clear my doubt..
regards
-Manish
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
You are right. The code should compile according to JSL. This a point where the compiler doesn't conform to the JLS. There is a bug report in Sun's database, and I think, it has been also commented here in the Ranch.


SCJP2. Please Indent your code using UBB Code
Manish Kumar
Ranch Hand

Joined: Apr 15, 2002
Posts: 53
Thanx Jose,
But should I expect this type of question in the exam?
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Not at all. They are careful enough in order not to show the possible bugs or inconsitencies of the compiler.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Instance Initializer, throw statement