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.RuntimeExceptionRepresents an exception that is a composite of one or more other exceptions. ACompositeExceptiondoes 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 classCompositeException.CompositeExceptionCausalChain(package private) static classCompositeException.PrintStreamOrWriter(package private) static classCompositeException.WrappedPrintStreamSame abstraction and implementation as in JDK to allow PrintStream and PrintWriter to share implementation(package private) static classCompositeException.WrappedPrintWriter
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Throwablecauseprivate java.util.List<java.lang.Throwable>exceptionsprivate java.lang.Stringmessageprivate static longserialVersionUID
-
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 voidappendStackTrace(java.lang.StringBuilder bldr, java.lang.Throwable ex, java.lang.String prefix)java.lang.ThrowablegetCause()java.util.List<java.lang.Throwable>getExceptions()Retrieves the list of exceptions that make up theCompositeExceptionprivate java.util.List<java.lang.Throwable>getListOfCauses(java.lang.Throwable ex)java.lang.StringgetMessage()private java.lang.ThrowablegetRootCause(java.lang.Throwable e)Returns the root cause ofe.voidprintStackTrace()All of the followingprintStackTracefunctionality is derived from JDKThrowableprintStackTrace.voidprintStackTrace(java.io.PrintStream s)voidprintStackTrace(java.io.PrintWriter s)private voidprintStackTrace(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 aListofThrowables
-
getMessage
public java.lang.String getMessage()
- Overrides:
getMessagein classjava.lang.Throwable
-
getCause
public java.lang.Throwable getCause()
- Overrides:
getCausein classjava.lang.Throwable
-
printStackTrace
public void printStackTrace()
All of the followingprintStackTracefunctionality is derived from JDKThrowableprintStackTrace. In particular, thePrintStreamOrWriterabstraction is copied wholesale. Changes from the official JDK implementation:- no infinite loop detection
- smaller critical section holding
PrintStreamlock - explicit knowledge about the exceptions
Listthat this loops through
- Overrides:
printStackTracein classjava.lang.Throwable
-
printStackTrace
public void printStackTrace(java.io.PrintStream s)
- Overrides:
printStackTracein classjava.lang.Throwable
-
printStackTrace
public void printStackTrace(java.io.PrintWriter s)
- Overrides:
printStackTracein 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 returneitself.- Parameters:
e- theThrowablee.- Returns:
- The root cause of
e. Ife.getCause()returns ore, just returneitself.
-
-