Errors

In Java, errors represent severe problems that are typically beyond the control of the application. These problems are not expected to be caught or handled by applications, as they usually indicate issues with the JVM or the system environment. Errors are subclasses of the Error class, which is itself a direct subclass of Throwable.

Errors are unchecked and should not be caught by a program (since they generally represent fatal conditions that the application cannot recover from).

Here’s the hierarchy of Errors in Java:


1. Throwable Class

  • The root class of both Exception and Error classes.

    • Throwable has two primary subclasses:

      • Error (for serious system issues that cannot be handled by the application)

      • Exception (for issues that can be handled, i.e., exceptions)


2. Error Class

  • Represents serious problems that are typically outside the scope of the program’s control. These are conditions that cannot be recovered from.

    • Errors do not require explicit handling in a program, and handling them is often not advisable, as they indicate a failure that the application cannot fix.


3. Common Subclasses of Error

Here are some commonly encountered errors in Java:

  • OutOfMemoryError:

    • Thrown when the Java Virtual Machine (JVM) runs out of memory and cannot allocate more.

  • StackOverflowError:

    • Thrown when the call stack (used for method calls) overflows, typically due to excessive recursion.

  • VirtualMachineError:

    • Thrown when the JVM is in an inconsistent or corrupted state and cannot continue execution.

  • InternalError:

    • Thrown when the JVM encounters an internal error, which might be caused by a bug in the JVM itself.

  • LinkageError:

    • Thrown when a class has some dependency conflict, usually because of changes in class versions (for example, loading the same class in different class loaders).

  • NoClassDefFoundError:

    • Thrown when a class that was present at compile-time cannot be found at runtime.

  • UnsatisfiedLinkError:

    • Thrown when a native method cannot be found in the specified library.

  • AssertionError:

    • Thrown when an assertion fails (used for debugging and testing).


Errors in Java are significant issues that typically arise from the underlying system or JVM. These issues are not meant to be caught or handled by Java programs, as they usually signal that the program cannot continue to execute. Common examples include OutOfMemoryError, StackOverflowError, and AssertionError. Errors usually require intervention at the system level or JVM adjustments, and handling them within the application code is not recommended.

Scroll to Top