Package io.reactivex.rxjava3.exceptions
Class CompositeException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- io.reactivex.rxjava3.exceptions.CompositeException
-
- All Implemented Interfaces:
java.io.Serializable
public final class CompositeException extends java.lang.RuntimeException
Represents an exception that is a composite of one or more other exceptions. ACompositeException
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 withgetExceptions()
. TheprintStackTrace()
implementation handles the StackTrace in a customized way instead of usinggetCause()
so that it can avoid circular references. If you invokegetCause()
, it will lazily create the causal chain but will stop if it finds any Throwable in the chain that it has already seen.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
CompositeException.ExceptionOverview
Contains a formatted message with a simplified representation of the exception graph contained within the CompositeException.(package private) static class
CompositeException.PrintStreamOrWriter
(package private) static class
CompositeException.WrappedPrintStream
Same abstraction and implementation as in JDK to allow PrintStream and PrintWriter to share implementation.(package private) static class
CompositeException.WrappedPrintWriter
Same abstraction and implementation as in JDK to allow PrintStream and PrintWriter to share implementation.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Throwable
cause
private java.util.List<java.lang.Throwable>
exceptions
private java.lang.String
message
private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description CompositeException(@NonNull java.lang.Iterable<? extends java.lang.Throwable> errors)
Constructs a CompositeException with the given array of Throwables as the list of suppressed exceptions.CompositeException(@NonNull java.lang.Throwable... exceptions)
Constructs a CompositeException with the given array of Throwables as the list of suppressed exceptions.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
appendStackTrace(CompositeException.PrintStreamOrWriter output, java.lang.Throwable ex, java.lang.String prefix)
@NonNull java.lang.Throwable
getCause()
@NonNull java.util.List<java.lang.Throwable>
getExceptions()
Retrieves the list of exceptions that make up theCompositeException
.@NonNull java.lang.String
getMessage()
void
printStackTrace()
All of the followingprintStackTrace
functionality is derived from JDKThrowable
printStackTrace
.private void
printStackTrace(CompositeException.PrintStreamOrWriter output)
Special handling for printing out aCompositeException
.void
printStackTrace(java.io.PrintStream s)
void
printStackTrace(java.io.PrintWriter s)
int
size()
Returns the number of suppressed exceptions.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
exceptions
private final java.util.List<java.lang.Throwable> exceptions
-
message
private final java.lang.String message
-
cause
private java.lang.Throwable cause
-
-
Constructor Detail
-
CompositeException
public CompositeException(@NonNull @NonNull java.lang.Throwable... exceptions)
Constructs a CompositeException with the given array of Throwables as the list of suppressed exceptions.- Parameters:
exceptions
- the Throwables to have as initially suppressed exceptions- Throws:
java.lang.IllegalArgumentException
- ifexceptions
is empty.
-
CompositeException
public CompositeException(@NonNull @NonNull java.lang.Iterable<? extends java.lang.Throwable> errors)
Constructs a CompositeException with the given array of Throwables as the list of suppressed exceptions.- Parameters:
errors
- the Throwables to have as initially suppressed exceptions- Throws:
java.lang.IllegalArgumentException
- iferrors
is empty.
-
-
Method Detail
-
getExceptions
@NonNull public @NonNull java.util.List<java.lang.Throwable> getExceptions()
Retrieves the list of exceptions that make up theCompositeException
.- Returns:
- the exceptions that make up the
CompositeException
, as aList
ofThrowable
s
-
getMessage
@NonNull public @NonNull java.lang.String getMessage()
- Overrides:
getMessage
in classjava.lang.Throwable
-
getCause
@NonNull public @NonNull java.lang.Throwable getCause()
- Overrides:
getCause
in classjava.lang.Throwable
-
printStackTrace
public void printStackTrace()
All of the followingprintStackTrace
functionality is derived from JDKThrowable
printStackTrace
. In particular, thePrintStreamOrWriter
abstraction is copied wholesale. Changes from the official JDK implementation:- no infinite loop detection
- smaller critical section holding
PrintStream
lock - explicit knowledge about the exceptions
List
that this loops through
- Overrides:
printStackTrace
in classjava.lang.Throwable
-
printStackTrace
public void printStackTrace(java.io.PrintStream s)
- Overrides:
printStackTrace
in classjava.lang.Throwable
-
printStackTrace
public void printStackTrace(java.io.PrintWriter s)
- Overrides:
printStackTrace
in classjava.lang.Throwable
-
printStackTrace
private void printStackTrace(CompositeException.PrintStreamOrWriter output)
Special handling for printing out aCompositeException
. Loops through all inner exceptions and prints them out.- Parameters:
output
- stream to print to
-
appendStackTrace
private void appendStackTrace(CompositeException.PrintStreamOrWriter output, java.lang.Throwable ex, java.lang.String prefix)
-
size
public int size()
Returns the number of suppressed exceptions.- Returns:
- the number of suppressed exceptions
-
-