Package rx.exceptions
Class CompositeException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- rx.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.CompositeExceptionCausalChain
(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
-
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(java.lang.String messagePrefix, java.util.Collection<? extends java.lang.Throwable> errors)
Deprecated.please useCompositeException(Collection)
CompositeException(java.lang.Throwable... errors)
Constructs a CompositeException instance with the supplied initial Throwables.CompositeException(java.util.Collection<? extends java.lang.Throwable> errors)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
appendStackTrace(java.lang.StringBuilder bldr, java.lang.Throwable ex, java.lang.String prefix)
java.lang.Throwable
getCause()
java.util.List<java.lang.Throwable>
getExceptions()
Retrieves the list of exceptions that make up theCompositeException
private java.util.List<java.lang.Throwable>
getListOfCauses(java.lang.Throwable ex)
java.lang.String
getMessage()
private java.lang.Throwable
getRootCause(java.lang.Throwable e)
Returns the root cause ofe
.void
printStackTrace()
All of the followingprintStackTrace
functionality is derived from JDKThrowable
printStackTrace
.void
printStackTrace(java.io.PrintStream s)
void
printStackTrace(java.io.PrintWriter s)
private void
printStackTrace(CompositeException.PrintStreamOrWriter s)
Special handling for printing out aCompositeException
.
-
-
-
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
@Deprecated public CompositeException(java.lang.String messagePrefix, java.util.Collection<? extends java.lang.Throwable> errors)
Deprecated.please useCompositeException(Collection)
Constructs a CompositeException with the given prefix and error collection.- Parameters:
messagePrefix
- the prefix to use (actually unused)errors
- the collection of errors
-
CompositeException
public CompositeException(java.util.Collection<? extends java.lang.Throwable> errors)
-
CompositeException
@Experimental public CompositeException(java.lang.Throwable... errors)
Constructs a CompositeException instance with the supplied initial Throwables.- Parameters:
errors
- the array of Throwables
-
-
Method Detail
-
getExceptions
public 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
public java.lang.String getMessage()
- Overrides:
getMessage
in classjava.lang.Throwable
-
getCause
public 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 s)
Special handling for printing out aCompositeException
. Loops through all inner exceptions and prints them out.- Parameters:
s
- stream to print to
-
appendStackTrace
private void appendStackTrace(java.lang.StringBuilder bldr, java.lang.Throwable ex, java.lang.String prefix)
-
getListOfCauses
private java.util.List<java.lang.Throwable> getListOfCauses(java.lang.Throwable ex)
-
getRootCause
private java.lang.Throwable getRootCause(java.lang.Throwable e)
Returns the root cause ofe
. Ife.getCause()
returns ore
, just returne
itself.- Parameters:
e
- theThrowable
e
.- Returns:
- The root cause of
e
. Ife.getCause()
returns ore
, just returne
itself.
-
-