-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.1
-
sparc
-
solaris_2.5
The inner classes white paper says that a checked exception may be raised
in an instance initializer if all constructors declare a throw for it,
and that the automatically generated constructor for an anonymous class
automatically throws the correct exceptions, so that any exception can be
raised in the body of an anonymous class.
The compiler produces several errors if this is attempted. Here is an example:
// this is JCK 1.1 test innr088
class InitExceptionBug0 {
void f() throws InstantiationException {
new Object() {
{
throw new InstantiationException("test");
}
};
}
}
The compiler output looks like this:
InitExceptionBug0.java:4: Statement not reached.
new Object() {
^
InitExceptionBug0.java:4: Constructor invocation must be the first thing in a method.
new Object() {
^
InitExceptionBug0.java:6: Exception java.lang.InstantiationException can't be thrown in initializer.
throw new InstantiationException("test");
^
3 errors
in an instance initializer if all constructors declare a throw for it,
and that the automatically generated constructor for an anonymous class
automatically throws the correct exceptions, so that any exception can be
raised in the body of an anonymous class.
The compiler produces several errors if this is attempted. Here is an example:
// this is JCK 1.1 test innr088
class InitExceptionBug0 {
void f() throws InstantiationException {
new Object() {
{
throw new InstantiationException("test");
}
};
}
}
The compiler output looks like this:
InitExceptionBug0.java:4: Statement not reached.
new Object() {
^
InitExceptionBug0.java:4: Constructor invocation must be the first thing in a method.
new Object() {
^
InitExceptionBug0.java:6: Exception java.lang.InstantiationException can't be thrown in initializer.
throw new InstantiationException("test");
^
3 errors
- duplicates
-
JDK-4054256 instance initializers should be able to throw exceptions
-
- Closed
-