exception chaining
Linking a new exception to the one that caused it, so the higher-level failure still carries the original error and its stack trace.
In more detail
In Java you pass the caught exception to the new exception's constructor, and in Python you write raise NewError(...) from err. Logs and tracebacks then show both the high-level failure and the low-level reason. Dropping the cause throws away the evidence that explains the failure.
Examples
StorageFailure(Throwable cause) { super(cause); }ex.getCause().getMessage()Related terms
- exception translation — Catching a low-level exception at a boundary and throwing a higher-level one that fits the caller's vocabulary, keeping the original as the cause.
- stack trace — The list of function calls that were running when an error happened, printed to help a developer find where it came from; Python calls it a traceback.
- exception — An error object a program raises to stop normal flow and report that something went wrong.
- raise statement — The statement that signals an error by creating and throwing an exception, as in raise ValueError("width must be positive").
- traceback — The report Python prints when an unhandled exception stops a program, listing the chain of calls that led there and ending with the error.
Taught in
- Checked Versus Unchecked Exceptions — Modern Java: Virtual Threads & High-Throughput Services
- The Cost Of Checked Exceptions — Modern Java: Virtual Threads & High-Throughput Services
- Async With CompletableFuture — Modern Java: Virtual Threads & High-Throughput Services
- Raising, And Writing Your Own Exception — Hands-on Python: Complete Video Course & Book
- Reading A Traceback Like A Professional — Hands-on Python: Complete Video Course & Book