Java Zero to All All questionsPractise free
Interview questions › Java Foundations — Zero to Basics › Exception Handling & Custom Exceptions

What is a suppressed exception and when do you encounter one in practice?

Level III · MidException Handling & Custom Exceptions
Short answer

A suppressed exception is a secondary exception attached to a primary one rather than masking it, accessible via Throwable.getSuppressed().

Explanation

The common source is try-with-resources: if the try body throws and then a resource's close() also throws, the close() exception is suppressed so the original is propagated. Knowing this matters in production debugging, because the real root cause is the primary exception and the suppressed array often shows cleanup failures that would otherwise look like the cause.

Common mistakes
  • Not knowing about getSuppressed() and losing the close() failure.
  • Thinking a suppressed exception replaces the primary one.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for Exception Handling & Custom Exceptions.

Practise free

More on Exception Handling & Custom Exceptions