-
Bug
-
Resolution: Fixed
-
P3
-
1.0.2, 1.1, 1.1.3
-
1.1
-
x86, sparc
-
solaris_2.4, windows_95
-
Not verified
Name: vsC45997 Date: 11/10/96
The section "14.16 The throw Statement" of The Java Language
Specification contains the following:
"If a throw statement is contained in a static initializer (8.5), then
a compile-time check ensures that either its value is always an
unchecked exception or its value is always caught by some try statement
that contains it. If, despite this check, the value is not caught by
some try statement that contains the throw statement, then the value
is rethrown if it is an instance of class Error or one of its
subclasses; otherwise, it is wrapped in an ExceptionInInitializerError
object, which is then thrown (12.4.2). "
The following examples show that exceptions thrown from a static
initializer are not caught. Class "stmt10701a" throws the instance of
"Error" class and class "stmt10702a" throws the instance of
"RuntimeException".
> javac -d . stmt10701.java
> java -verify javasoft.sqe.tests.lang.stmt107.stmt10701.stmt10701
before
java.lang.Error
at javasoft.sqe.tests.lang.stmt107.stmt10701.stmt10701a.<clinit>(stmt10701.java:30)
at javasoft.sqe.tests.lang.stmt107.stmt10701.stmt10701.run(stmt10701.java:11)
at javasoft.sqe.tests.lang.stmt107.stmt10701.stmt10701.main(stmt10701.java:5)
after
failed
> javac -d . stmt10702.java
> java -verify javasoft.sqe.tests.lang.stmt107.stmt10702.stmt10702
before
java.lang.RuntimeException
at javasoft.sqe.tests.lang.stmt107.stmt10702.stmt10702a.<clinit>(stmt10702.java:30)
at javasoft.sqe.tests.lang.stmt107.stmt10702.stmt10702.run(stmt10702.java:11)
at javasoft.sqe.tests.lang.stmt107.stmt10702.stmt10702.main(stmt10702.java:5)
after
failed
--------------------------stmt10701.java------------------------------
package javasoft.sqe.tests.lang.stmt107.stmt10701;
import java.io.PrintStream;
public class stmt10701 {
public static void main(String argv[]) {
System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
}
public static int run(String argv[],PrintStream out) {
int a1 = 1;
int aa = 1;
try {
out.println(" before");
aa = stmt10701a.a2;
out.println(" after");
}
catch (Error e) {
out.println(e);
a1 = 2;
}
catch (Throwable e) {
out.println(e);
}
if ( a1!=2 ) {
out.println("failed");
return 2;
}
return 0;
}
}
class stmt10701a {
static Error a = new Error();
static int a1;
static int a2 = 1;
static { a1 = 1;
if ( a1 == 1 )
throw a;
else
a2 = 2;
}
}
-----------------------------------------------------------------
--------------------------stmt10702.java-----------------------------
package javasoft.sqe.tests.lang.stmt107.stmt10702;
import java.io.PrintStream;
public class stmt10702 {
public static void main(String argv[]) {
System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
}
public static int run(String argv[],PrintStream out) {
int a1 = 1;
int aa = 1;
try {
out.println(" before");
aa = stmt10702a.a2;
out.println(" after");
}
catch (RuntimeException e) {
out.println(e);
a1 = 2;
}
catch (Throwable e) {
out.println(e);
}
if ( a1!=2 ) {
out.println("failed");
return 2;
}
return 0;
}
}
class stmt10702a {
static RuntimeException a = new RuntimeException();
static int a1;
static int a2 = 1;
static { a1 = 1;
if ( a1 == 1 )
throw a;
else
a2 = 2;
}
}
-----------------------------------------------------------------
======================================================================
- duplicates
-
JDK-4013900 java.lang.ExceptionInInitializerError is not implemented
- Closed
-
JDK-4070379 ExceptionInInitializerError not always thrown.
- Closed