New Exception vs Rethrow in Java
Fast recall
Quick revision
Core answer
throw e; rethrows the same object and keeps its type, message, cause, and existing stack trace. Throwing a new object creates a new type, message, and stack origin; when translating an existing failure, pass it as the cause. Create a new exception only when the new abstraction or context helps the caller—wrapping at every layer adds noise.Whether you can choose between propagating the same exception and wrapping it, and know to preserve the cause when wrapping
Wrapping in a new exception without the cause, or wrapping unnecessarily when the original was already meaningful
Explain the layer-translation rationale: wrap at boundaries to give callers a stable, meaningful exception type
Interview-ready guide
Interview answer
Rethrowing with throw e sends the same exception object onward and preserves its existing cause and diagnostic information. Wrapping creates a new outer exception at the translation point, so it is useful when a lower-level failure needs a meaning that fits the current API. The original exception should be passed as the cause.
For example, a repository can catch SQLException and throw new OrderStoreException("Could not load order " + id, e) because callers should depend on the repository abstraction rather than JDBC. If a method catches OrderStoreException but cannot add context or handle it, simply letting it propagate is clearer than wrapping it again. I also avoid catching only to log and rethrow; logging normally belongs at the boundary that finally handles or reports the failure.
New Exception vs Rethrow in Java
Direct Answer
throw e; rethrows the same object and keeps its type, message, cause, and existing stack trace. Throwing a new object creates a new type, message, and stack origin; when translating an existing failure, pass it as the cause. Create a new exception only when the new abstraction or context helps the caller—wrapping at every layer adds noise.
Common Mistakes & Pitfalls
- Wrapping without the cause —
new X(msg)instead ofnew X(msg, e)throws away the root trace. - Over-wrapping — translating an already-meaningful exception just adds noise.
- Coupling callers to low-level types — rethrowing a raw
SQLExceptionpast a boundary leaks JDBC. - Logging at every layer — log once at the boundary instead of duplicating entries up the stack.
Check your understanding
Answer these without looking back at the article.
- How does getCause() relate to exception chaining?
- When should you rethrow the same exception vs wrapping it?
- How do logging frameworks handle exception causes?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.