public final class CompositeException
extends java.lang.RuntimeException
CompositeException
does not modify the structure of any exception it wraps, but at print-time it iterates through the list of
Throwables contained in the composite in order to print them all.
Its invariant is to contain an immutable, ordered (by insertion order), unique list of non-composite
exceptions. You can retrieve individual exceptions in this list with getExceptions()
.
The printStackTrace()
implementation handles the StackTrace in a customized way instead of using
getCause()
so that it can avoid circular references.
If you invoke getCause()
, it will lazily create the causal chain but will stop if it finds any
Throwable in the chain that it has already seen.Constructor and Description |
---|
CompositeException()
Constructs an empty CompositeException.
|
CompositeException(java.lang.Iterable<? extends java.lang.Throwable> errors)
Constructs a CompositeException with the given array of Throwables as the
list of suppressed exceptions.
|
CompositeException(java.lang.Throwable... exceptions)
Constructs a CompositeException with the given array of Throwables as the
list of suppressed exceptions.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Throwable |
getCause() |
java.util.List<java.lang.Throwable> |
getExceptions()
Retrieves the list of exceptions that make up the
CompositeException . |
java.lang.String |
getMessage() |
boolean |
isEmpty()
Returns true if this CompositeException doesn't have a cause or
any suppressed exceptions.
|
void |
printStackTrace()
All of the following
printStackTrace functionality is derived from JDK Throwable
printStackTrace . |
void |
printStackTrace(java.io.PrintStream s) |
void |
printStackTrace(java.io.PrintWriter s) |
int |
size()
Returns the number of suppressed exceptions.
|
void |
suppress(java.lang.Throwable e)
Adds a suppressed exception to this composite.
|
public CompositeException()
public CompositeException(java.lang.Throwable... exceptions)
exceptions
- the Throwables to have as initially suppressed exceptionspublic CompositeException(java.lang.Iterable<? extends java.lang.Throwable> errors)
errors
- the Throwables to have as initially suppressed exceptionspublic java.util.List<java.lang.Throwable> getExceptions()
CompositeException
.CompositeException
, as a List
of Throwable
spublic java.lang.String getMessage()
getMessage
in class java.lang.Throwable
public void suppress(java.lang.Throwable e)
The method is named this way to avoid conflicts with Java 7 environments and its addSuppressed() method.
e
- the exception to suppress, nulls are converted to NullPointerExceptionspublic java.lang.Throwable getCause()
getCause
in class java.lang.Throwable
public void printStackTrace()
printStackTrace
functionality is derived from JDK Throwable
printStackTrace
. In particular, the PrintStreamOrWriter
abstraction is copied wholesale.
Changes from the official JDK implementation:PrintStream
lockList
that this loops throughprintStackTrace
in class java.lang.Throwable
public void printStackTrace(java.io.PrintStream s)
printStackTrace
in class java.lang.Throwable
public void printStackTrace(java.io.PrintWriter s)
printStackTrace
in class java.lang.Throwable
public int size()
public boolean isEmpty()