Sitemap
Javarevisited

A humble place to learn Java and Programming better.

Member-only story

Can You Catch an in Java | Tricky Java Interview Questions — Part 17

2 min read4 days ago

--

Hello Developers,

Welcome to Part 17 of the Tricky Java Interview Questions series.

Today’s question explores Java’s exception mechanism — specifically around the often-confused class called :

Can you catch an in Java?

Let’s cut straight to it:

✅ Short Answer

Yes, you can catch an in Java using a block.
But it’s almost always a
bad idea to do so.

Let’s understand what really is, and why Java allows it — even though you're almost never supposed to use it that way.

Java Exception Hierarchy Recap

In Java, everything that can be thrown inherits from .

             Throwable
/ \
Error Exception
  • Exception: For conditions your code should try to handle (e.g., , )
  • Error: For conditions your code should NOT try to handle (e.g., , )

✅ Yes, Is Catchable

public class CatchErrorExample {
public static void main(String[] args) {
try {
throw new StackOverflowError("Custom SOE");
} catch (Error e) {
System.out.println("Caught Error: "…
Javarevisited
Javarevisited

Published in Javarevisited

A humble place to learn Java and Programming better.

Meena Jadhav
Meena Jadhav

Written by Meena Jadhav

Python Lover | Soft Skills | Freelancing | Women in tech | Programming | AI | Web | Java | Working with the Java Guides Team -

No responses yet