Course contentsShow
← Java
Lesson 782 of 2,87019. Exception Hierarchy and Custom ExceptionsFree lesson

VirtualMachineError and LinkageError: System-Level Errors

Explore critical Error subclasses like OutOfMemoryError, StackOverflowError, NoClassDefFoundError, and when they occur.

VirtualMachineError and LinkageError: System-Level Errors

What You'll Learn

You'll understand the critical Error subclasses that signal catastrophic JVM problems you usually can't—and shouldn't—recover from in application code.

The Two Major System-Level Error Categories

Recall that Error extends Throwable but represents serious problems beyond typical application control. Two key branches stand out:

VirtualMachineError: JVM Resource Exhaustion

VirtualMachineError signals that the Java Virtual Machine itself is in trouble:

OutOfMemoryError — The JVM has exhausted available heap memory and cannot allocate more objects. This typically means your application created too many objects or has a memory leak.

StackOverflowError — The call stack has exceeded its maximum depth, usually from infinite recursion (a method calling itself endlessly without a proper base case).

InternalError — Something went critically wrong inside the JVM itself.

LinkageError: Class Loading Failures

LinkageError occurs when the JVM cannot properly link classes at runtime:

NoClassDefFoundError — A class was available at compile time but missing at runtime. Perhaps the .class file was deleted or classpath is misconfigured.

ClassFormatError — A .class file is corrupted or has an incompatible format.

UnsatisfiedLinkError — Native method dependency cannot be found.

Why You Rarely Catch These

These errors signal conditions so severe that attempting recovery is usually futile. OutOfMemoryError means you have no memory left; catching it won't magically create memory. StackOverflowError means your call stack is exhausted—you're already in crisis mode. These belong to cleanup and logging, not business logic recovery.

Key Takeaway: VirtualMachineError (like OutOfMemoryError and StackOverflowError) and LinkageError (like NoClassDefFoundError) represent critical JVM-level failures that generally indicate configuration problems, resource exhaustion, or environmental issues—catching them is rarely appropriate in application code.