What happens when an exception is thrown in a static initialization block?

When a static initialization block throws an exception, the JVM wraps it in an ExceptionInInitializerError and marks the class as having failed initialization, meaning the class can never be successfully initialized in that JVM for the rest of its run.

Key Points

Example

A class with a static block that parses a configuration value and throws a NumberFormatException on bad input will fail to initialize; every later reference to that class anywhere in the application then throws NoClassDefFoundError, even in code paths unrelated to the original config parsing.

Interview Tip

A concise interview answer is

An exception thrown in a static initializer gets wrapped in an ExceptionInInitializerError, and the class is permanently marked as failed to initialize for that JVM run. Any later attempt to use the class throws NoClassDefFoundError instead, which is why static initializers should avoid operations that can fail unless a hard startup failure is actually the intended behavior.

Last updated: 16 July 2026

Next question: Give an example of when you would deliberately use a checked exception instead of an unchecked one.

More Exception Handling interview questions

All Exception Handling questions