Learn Java
import com.learnjava.exceptionhandling.ErrorsVsExceptions;

Errors vs Exceptions in Java

@Concept

Throwable is the root of Java's entire exception hierarchy, splitting immediately into two very different branches: Error and Exception. An Error represents a serious problem an application generally shouldn't try to catch or recover from at all — OutOfMemoryError or StackOverflowError signal that the JVM itself is in genuine trouble, and application code catching these rarely helps.

An Exception represents a problem a program can reasonably anticipate and often recover from — a file that doesn't exist, invalid user input, a network request that failed. This three-way split — Error, checked Exception, and unchecked Exception (RuntimeException) — exists specifically to separate "the JVM is in serious trouble" from "something expected went wrong" from "this is very likely a programming bug," and knowing which bucket a problem falls into shapes whether catching it is even the right response.

@HowItWorks
1

Throwable is the root

Every single thing that can be thrown in Java, Error and Exception alike, ultimately extends Throwable.

2

Error

Signals a serious problem, typically with the JVM itself, that application code generally shouldn't try to catch or recover from.

3

Exception

Signals a problem a program can reasonably anticipate and often meaningfully recover from.

4

Checked versus unchecked Exception

A further split within Exception, covered in depth in its own topic.

5

Deciding what to do with a given problem

Depends heavily on which of these categories it actually falls into, not just whether it's technically catchable.

@Example
public class ErrorVsExceptionDemo {
public static void main(String[] args) {
try {
int[] numbers = new int[3];
System.out.println(numbers[5]);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Caught an Exception: " + e.getMessage());
}
}
}
Output
Caught an Exception: Index 5 out of bounds for length 3
1numbers[5] tries to access an index that doesn't exist in a 3-element array, exactly the kind of anticipatable problem an Exception represents.
2ArrayIndexOutOfBoundsException, a subclass of Exception, is thrown rather than crashing the whole program immediately.
3The catch block catches it specifically, since its declared type matches the thrown exception's actual type.
4getMessage() returns the exception's descriptive text, which the single println call then prints.
@UseCases
Deciding whether a given problem is worth catching and handling versus letting the program stop
Recognizing that an OutOfMemoryError usually isn't something application code should try to catch
Understanding why ArrayIndexOutOfBoundsException is an Exception, not an Error, despite sounding serious
Reading a stack trace and identifying which branch of Throwable the actual problem came from

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in Java yourself — building beats watching.