aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception and Instance Initializer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception and Instance Initializer" Watch "Exception and Instance Initializer" New topic

Exception and Instance Initializer

Rekha Rao

Joined: Jan 23, 2001
Posts: 15
From JLS 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.
I thought the following code should compile. What is wrong here ?
public class Test{
// I get an error here: unreported exception TestException; must be caught or declared to //be thrown
void print() throws TestException{
Test() throws TestException{
class TestException extends Exception{}
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
This is a bug in Java Bug database:
It is fixed in Java Merlin release

SCJP2. Please Indent your code using UBB Code
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
As a consequence I don't think we'll be asked for it in the
exam ;-)
Have you tried LearnNowOnline?
subject: Exception and Instance Initializer