Search This Blog

Java Exceptions Catalog Part 1: Complete Guide to JVM Errors & Runtime Exceptions

Java Exceptions Catalog - Part 1: java.lang Errors & Runtime Exceptions

Java Exceptions Catalog - Part 1: Core java.lang Package

Comprehensive guide to all fatal JVM errors (java.lang.Error subclasses) and unchecked runtime exceptions (java.lang.RuntimeException subclasses).

1. JVM Fatal Errors (java.lang.Error Hierarchy)

FATAL

java.lang.OutOfMemoryError

The JVM cannot allocate an object because it is out of memory and no more memory could be made available by garbage collection.

Resolution
Increase heap allocation using -Xmx, fix static collection leaks, or analyze heap dumps via Eclipse MAT / JProfiler.
FATAL

java.lang.StackOverflowError

A thread call stack has overflowed due to excessive or infinite recursion.

Resolution
Ensure proper base termination conditions in recursive methods or refactor logic into iterative loops.
FATAL

java.lang.NoClassDefFoundError

The JVM or ClassLoader instance tries to load in the definition of a class and no definition of the class could be found.

Resolution
Ensure all required dependencies are packaged into the final JAR/WAR artifact and present on the execution classpath.
FATAL

java.lang.UnsatisfiedLinkError

The JVM cannot locate an appropriate native language library file (e.g., .so, .dll, .dylib) bound via JNI.

Resolution
Verify native library paths set via -Djava.library.path system properties.
FATAL

java.lang.ExceptionInInitializerError

An unhandled exception occurred during the evaluation of a static initializer block or static variable assignment.

Resolution
Check all static { ... } blocks for potential null pointers, array overflows, or uncaught exceptions.
FATAL

java.lang.NoSuchMethodError

An application attempts to call a method that does not exist in the loaded class version at runtime (JAR version mismatch).

FATAL

java.lang.NoSuchFieldError

An application attempts to access a field variable that no longer exists in the target class definition.

FATAL

java.lang.AbstractMethodError

Invoking an abstract method that was not implemented by the loaded concrete subclass at runtime.

FATAL

java.lang.UnsupportedClassVersionError

Attempting to run a class file compiled with a newer JDK release on an older JRE runtime.

FATAL

java.lang.VerifyError

Bytecode verifier detects a class file containing corrupt or malformed bytecode instructions.

FATAL

java.lang.ClassFormatError

The JVM attempts to read a class file and determines that the file is corrupted or untruncated.

FATAL

java.lang.ClassCircularityError

A circular dependency loop is detected among classes during initialization (e.g., Class A extends B, B extends A).

FATAL

java.lang.AssertionError

An assert statement failed during execution when JVM assertions are enabled (`-ea`).

FATAL

java.lang.ThreadDeath

Thrown automatically when a thread is stopped using the deprecated Thread.stop() method.

FATAL

java.lang.InternalError

An unexpected native internal fault occurred within the underlying JVM implementation.

FATAL

java.lang.UnknownError

An unknown but serious error occurred inside the virtual machine infrastructure.

FATAL

java.lang.BootstrapMethodError

An invokedynamic instruction or bootstrap method fails to locate or execute its target method handle.

2. Unchecked Core Runtime Exceptions (java.lang.RuntimeException Hierarchy)

RUNTIME

java.lang.NullPointerException

Attempting to invoke a method, access a field, or measure length on a null reference.

Resolution
Use null guards (if (obj != null)), Optional<T> wrappers, or Objects.requireNonNull() checks.
RUNTIME

java.lang.ArrayIndexOutOfBoundsException

Accessing an array index that is negative or greater than/equal to the array size.

Resolution
Check array index logic to ensure index < array.length before accessing elements.
RUNTIME

java.lang.StringIndexOutOfBoundsException

Accessing character indices on a String object that are negative or exceed string length.

RUNTIME

java.lang.ClassCastException

Casting an object to a subclass type of which it is not an instance.

Resolution
Use Java pattern matching for instanceof checks prior to casting operations.
RUNTIME

java.lang.NumberFormatException

Attempting to convert an invalid String into a numeric primitive (e.g., Integer.parseInt("abc")).

Resolution
Sanitize strings with regex or catch NumberFormatException explicitly during string parsing.
RUNTIME

java.lang.IllegalArgumentException

Passing an illegal or inappropriate argument value to a method invocation.

RUNTIME

java.lang.IllegalStateException

Invoking a method when the application state is invalid for that operation.

RUNTIME

java.lang.ArithmeticException

An exceptional arithmetic condition occurred (e.g., integer division by zero: 10 / 0).

RUNTIME

java.lang.ArrayStoreException

Attempting to store an incompatible object type inside an array of objects (e.g., putting Integer into String[]).

RUNTIME

java.lang.NegativeArraySizeException

Attempting to instantiate an array with a negative size dimension (e.g., new int[-5]).

RUNTIME

java.lang.UnsupportedOperationException

Calling an unsupported method on an object (e.g., calling .add() on an unmodifiable list).

RUNTIME

java.lang.SecurityException

Thrown by SecurityManager when an unauthorized operation (e.g., restricted file read) is attempted.

RUNTIME

java.lang.TypeNotPresentException

Application attempts to access a type using a String name, but the definition cannot be found.

RUNTIME

java.lang.EnumConstantNotPresentException

An application attempts to access an enum constant by name, but the enum type contains no constant with that name.

RUNTIME

java.lang.IllegalMonitorStateException

Calling wait(), notify(), or notifyAll() without holding the object's monitor lock.

RUNTIME

java.lang.IllegalThreadStateException

Attempting to start a thread that has already been started or terminated.

No comments:

Post a Comment