Reputation: 67800
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.
Upvotes: 4
Views: 197
Reputation: 22435
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;
}
Upvotes: 4
Reputation: 692071
What you're doing is commonly called "exception chaining". I was introduced in Java 1.4.
Upvotes: 1
Reputation: 68992
It is called re-throwing or exception-translating to harmonize different api's to an abstracter one (often done in the spring framework).
Upvotes: 3
Reputation: 10325
I believe I've seen that referred to as wrapping an Exception. Sorry if that's not the term you're looking for.
Upvotes: 1
Reputation: 24895
I use "rethrow" without any shame.
Anyway what you are doing is encapsulating the exception inside a new one.
Upvotes: 2