What is the term for catching and reorganizing Java exceptions?

I seem to remember a very specific term for such situations:

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 would like to use this correct term in some documents. Can anyone skip my memory?


EDIT: As I understand it, the link provided by JB Nizet chain 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 this is not the concept I'm looking for. Sorry if my question turned out to be fraudulent.

+4
source share
7 answers

In response to your editing: in this case, you simply throw an exception. It just happens in a catch block. Instead of using potentially confusing terminology such as β€œtransformation” (which, I think, implies a mutation, not something new), I suggest you just say what you are doing explicitly.


You "wrap" the caught exception to another. Another term for it is "exception chain"

Notice that the repeated exception is different from the other, because you are not creating a new exception, just catch it to make some entries (or something else) and then throw them away again. To demonstrate:

 try { operation(); } catch (SomeException se) { throw se; } 
+4
source

It is called re-throwing or exception-translating to match different api with abstract ones (often executed as part of spring).

+3
source

I use "rethrow" without shame.

In any case, what you do is encapsulate the exception inside the new one.

+2
source

Exception wrapper or exception chain

+2
source

I believe that I saw that this is called the flow around the Exception. Sorry if this is not the term you are looking for.

+1
source

What you do is usually called an "exception chain . " I was introduced in Java 1.4 .

+1
source

It is also called

Exception chain

+1
source

All Articles