-
Enhancement
-
Resolution: Won't Fix
-
P4
-
None
-
1.1.6
-
x86
-
windows_nt
Name: dbT83986 Date: 02/01/99
Try compiling the following code:
public class SimpleTest
{
SimpleTest() throws Throwable
{
super();
}
public static void main( String[] args )
{
try
{
SimpleTest test = new SimpleTest() {};
}
catch ( Throwable t )
{
t.printStackTrace();
}
}
}
This results in an error: "SimpleTest.java: 11
Exception java.lang.Throwable must be caught, or
it must be declared in the throws clause of this
method."
There is a catch for Throwable so why is it
complaining? I think it is implicitly creating a
constructor for the anonymous class that calls
SimpleTest's constructor. But this implicit
constructor does not throw the exception, hence
the error.
==============================
REVIEW NOTE 2/1/99 - User responded requesting filing as RFE
I would still like to be able to create anonymous classes from classes whose constructors
throw exceptions. This doesn't seem particularly difficult to implement: simply pass the
exceptions on as the arguments are currently passed on. Can you submit this as an RFE
please?
Also, I don't think the nested classes spec. mentions constructor exceptions, so
that could be clarified too.
(Review ID: 35230)
======================================================================
- relates to
-
JDK-4350863 Anonymous class fails to compile if superclass's constructor throws exception
-
- Closed
-