Exception Thrown Inside Catch Block
Fast recall
Quick revision
Core answer
catch block throws (or rethrows) an exception, that new exception propagates out of the whole try statement as if the try had thrown it — the other catch blocks of the same try are not considered. The finally block still runs first. If both the catch and finally throw, the finally's exception wins and the catch's is lost (unless you chain it).Whether you know sibling catch blocks don't catch each other and that finally still runs and can override the catch's exception
Expecting another catch block of the same try to handle an exception thrown inside a catch
Explain the finally-overrides-catch case and how to preserve the original by chaining (passing it as the cause)
Interview-ready guide
Interview answer
If an exception is thrown inside a catch block, that new exception propagates out of the entire try statement, just as if the try block itself had thrown it.
The key thing people get wrong is assuming that one of the other catch blocks attached to the same try will catch it. They won't. Sibling catch blocks only handle exceptions that come from the try body — they don't catch exceptions thrown by each other.
So once you're inside a catch and you throw, you're leaving this try statement entirely, and it's the caller's job to handle the new exception. This happens in two ways. Sometimes it's accidental — for instance, while building your error message in the catch you dereference something null and get a NullPointerException, which then masks the original error.
And sometimes it's deliberate, like when you catch a low-level exception and wrap it in a domain-specific one and rethrow. When you do that deliberately, you should always pass the original exception in as the cause, so the chain is preserved and getCause can recover it later. Now, as control leaves the try statement, its finally block normally runs before the new exception continues.
But here's a sharp edge: if the finally block itself throws an exception, that one wins, and it silently replaces whatever the catch was throwing. So you lose the real error. That's exactly why throwing from finally is dangerous because it can replace the pending failure.
To sum up: an exception in a catch escapes the whole try, siblings don't help, finally normally runs on exit, and if finally throws it overrides everything — so keep finally simple and chain your causes when you rethrow.
Exception Thrown Inside Catch Block
Direct Answer
If a catch block throws (or rethrows) an exception, that new exception propagates out of the whole try statement as if the try had thrown it — the other catch blocks of the same try are not considered. The finally block still runs first. If both the catch and finally throw, the finally's exception wins and the catch's is lost (unless you chain it).
Code Example
public class CatchThrows {
void demo() {
try {
throw new IOException("disk read failed");
} catch (IOException e) {
// Wrap and rethrow as a domain exception, keeping the cause
throw new DataAccessException("could not load data", e);
} catch (RuntimeException e) {
// NOT reached for the IOException above -- siblings don't chain
handle(e);
} finally {
System.out.println("runs before DataAccessException propagates");
}
}
}
DataAccessException escapes the method; the second catch never sees it because it came from the first catch, not the try.
Common Mistakes & Pitfalls
- Expecting a sibling
catchto handle it. Other catches of the sametryonly see exceptions from thetrybody. - Throwing from
finally. It overrides thecatch's exception and loses the real error. - Rethrowing without the cause.
throw new XException(msg)drops the original — usethrow new XException(msg, e). - Building messages that NPE. A null field in the
catch's message logic throws a new exception, masking the first.
Check your understanding
Answer these without looking back at the article.
- What is the difference between rethrowing the same exception and wrapping it?
- How do you rethrow the original exception without wrapping it?
- What does it mean to preserve the exception chain?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.