Error vs Exception in Java
Fast recall
Quick revision
Core answer
Error and Exception extend Throwable. Exception is the branch application APIs commonly use for conditions they may handle. Error represents serious conditions an ordinary application usually should not catch, such as linkage failures or resource exhaustion. Avoid blanket catch (Throwable); rare infrastructure cleanup code may catch broadly only if it promptly rethrows what it cannot safely handle.Whether you understand recoverability — that Error signals a broken JVM you let propagate, while Exception signals conditions your code can handle
Catching Error (or Throwable) like a normal Exception, and assuming Errors only come from outside your code
Point out StackOverflowError is caused by YOUR recursion yet you still shouldn't catch it — the fix is the code, not a catch block
Interview-ready guide
Interview answer
Error and Exception are the two direct branches under Throwable, but Java APIs use them for different kinds of conditions. Error is unchecked and represents serious conditions such as resource exhaustion, linkage problems, stack overflow, or failed assertions. Ordinary application code usually cannot repair these and lets them propagate.
Exception is the branch commonly used by application and library failure contracts. It includes checked types such as IOException and unchecked RuntimeException types such as IllegalArgumentException. For example, a request boundary may catch a specific application exception and map it to a response, while it would normally not turn OutOfMemoryError into an ordinary business result. I still avoid absolute labels: the concrete type and the boundary determine what can be handled safely.
Error vs Exception in Java
Direct Answer
Both Error and Exception extend Throwable. Exception is the branch application APIs commonly use for conditions they may handle. Error represents serious conditions an ordinary application usually should not catch, such as linkage failures or resource exhaustion. Avoid blanket catch (Throwable); rare infrastructure cleanup code may catch broadly only if it promptly rethrows what it cannot safely handle.
Common Mistakes & Pitfalls
- Saying every Error means a corrupted JVM: Error covers different serious conditions; ordinary code usually cannot recover, but the statement is not universal.
- Saying every Exception is recoverable:
Exceptionincludes checked and runtime failures, and the caller may have no recovery. - Catching
Throwableas a safety net: it also intercepts Error and should be limited to a carefully designed boundary. - Swallowing after logging: if the boundary cannot handle the condition, preserve it by rethrowing.
- Ignoring specific types: handling should follow the concrete contract, not only the top-level branch.
Check your understanding
Answer these without looking back at the article.
- Can you give an example where catching an Error might make sense?
- What causes StackOverflowError?
- What is OutOfMemoryError and how do you diagnose it?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.