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)
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.
-Xmx, fix static collection leaks, or analyze heap dumps via Eclipse MAT / JProfiler.java.lang.StackOverflowError
A thread call stack has overflowed due to excessive or infinite recursion.
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.
java.lang.UnsatisfiedLinkError
The JVM cannot locate an appropriate native language library file (e.g., .so, .dll, .dylib) bound via JNI.
-Djava.library.path system properties.java.lang.ExceptionInInitializerError
An unhandled exception occurred during the evaluation of a static initializer block or static variable assignment.
static { ... } blocks for potential null pointers, array overflows, or uncaught exceptions.java.lang.NoSuchMethodError
An application attempts to call a method that does not exist in the loaded class version at runtime (JAR version mismatch).
java.lang.NoSuchFieldError
An application attempts to access a field variable that no longer exists in the target class definition.
java.lang.AbstractMethodError
Invoking an abstract method that was not implemented by the loaded concrete subclass at runtime.
java.lang.UnsupportedClassVersionError
Attempting to run a class file compiled with a newer JDK release on an older JRE runtime.
java.lang.VerifyError
Bytecode verifier detects a class file containing corrupt or malformed bytecode instructions.
java.lang.ClassFormatError
The JVM attempts to read a class file and determines that the file is corrupted or untruncated.
java.lang.ClassCircularityError
A circular dependency loop is detected among classes during initialization (e.g., Class A extends B, B extends A).
java.lang.AssertionError
An assert statement failed during execution when JVM assertions are enabled (`-ea`).
java.lang.ThreadDeath
Thrown automatically when a thread is stopped using the deprecated Thread.stop() method.
java.lang.InternalError
An unexpected native internal fault occurred within the underlying JVM implementation.
java.lang.UnknownError
An unknown but serious error occurred inside the virtual machine infrastructure.
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)
java.lang.NullPointerException
Attempting to invoke a method, access a field, or measure length on a null reference.
if (obj != null)), Optional<T> wrappers, or Objects.requireNonNull() checks.java.lang.ArrayIndexOutOfBoundsException
Accessing an array index that is negative or greater than/equal to the array size.
index < array.length before accessing elements.java.lang.StringIndexOutOfBoundsException
Accessing character indices on a String object that are negative or exceed string length.
java.lang.ClassCastException
Casting an object to a subclass type of which it is not an instance.
instanceof checks prior to casting operations.java.lang.NumberFormatException
Attempting to convert an invalid String into a numeric primitive (e.g., Integer.parseInt("abc")).
NumberFormatException explicitly during string parsing.java.lang.IllegalArgumentException
Passing an illegal or inappropriate argument value to a method invocation.
java.lang.IllegalStateException
Invoking a method when the application state is invalid for that operation.
java.lang.ArithmeticException
An exceptional arithmetic condition occurred (e.g., integer division by zero: 10 / 0).
java.lang.ArrayStoreException
Attempting to store an incompatible object type inside an array of objects (e.g., putting Integer into String[]).
java.lang.NegativeArraySizeException
Attempting to instantiate an array with a negative size dimension (e.g., new int[-5]).
java.lang.UnsupportedOperationException
Calling an unsupported method on an object (e.g., calling .add() on an unmodifiable list).
java.lang.SecurityException
Thrown by SecurityManager when an unauthorized operation (e.g., restricted file read) is attempted.
java.lang.TypeNotPresentException
Application attempts to access a type using a String name, but the definition cannot be found.
java.lang.EnumConstantNotPresentException
An application attempts to access an enum constant by name, but the enum type contains no constant with that name.
java.lang.IllegalMonitorStateException
Calling wait(), notify(), or notifyAll() without holding the object's monitor lock.
java.lang.IllegalThreadStateException
Attempting to start a thread that has already been started or terminated.
No comments:
Post a Comment