If a static field initializer or static block throws, the class fails to load and the JVM reports it as an ExceptionInInitializerError, an Error rather than an Exception, with the real cause reachable via getCause.
class Broken {
static final int VALUE = 10 / Integer.parseInt("0");
}
try {
int v = Broken.VALUE;
System.out.println("Unreachable: " + v);
} catch (ExceptionInInitializerError e) {
System.out.println(e.getClass().getSimpleName() + " caused by " + e.getCause().getClass().getSimpleName() + ": " + e.getCause().getMessage());
}
ExceptionInInitializerError caused by ArithmeticException: / by zero
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-09-27