I seem to remember a very specific term for situations like this:
try {
operation();
} catch (SomeException se) {
throw new OtherException(se);
}
-or-
try {
operation();
} catch (SomeException se) {
throw new OtherException("new message, forget original exception");
}
and I'd like to use that correct term in some documentation. Can someone please jog my memory?
EDIT: As I understand the link quoted by JB Nizet, chaining is the act of passing the original exception to the constructor of the new one so the stack trace will include the original one. But that's not the concept I'm looking for. Sorry if my question ended up being misleading this way.
In response to your edit: In that case, you're just "throwing" an exception. It just so happens to be thrown in a catch block. Instead of using potentially confusing terminology such as "transforming" (which I think implies mutation, rather than something new), I suggest you just say what you are doing explicitly.
You are "wrapping" the caught exception with another. Another term for it is "exception chaining"
Note, that rethrowing an exception is different because you are not creating a new exception, just catching it to do some logging (or something) and then throwing it again. To demonstrate:
try {
operation();
}
catch (SomeException se) {
throw se;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With