Package rx.exceptions

Class 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. A 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.
    See Also:
    Serialized Form
    • Field Detail

      • 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.
        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 the CompositeException
        Returns:
        the exceptions that make up the CompositeException, as a List of Throwables
      • getMessage

        public java.lang.String getMessage()
        Overrides:
        getMessage in class java.lang.Throwable
      • getCause

        public java.lang.Throwable getCause()
        Overrides:
        getCause in class java.lang.Throwable
      • printStackTrace

        public void printStackTrace()
        All of the following printStackTrace functionality is derived from JDK Throwable printStackTrace. In particular, the PrintStreamOrWriter 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 class java.lang.Throwable
      • printStackTrace

        public void printStackTrace​(java.io.PrintStream s)
        Overrides:
        printStackTrace in class java.lang.Throwable
      • printStackTrace

        public void printStackTrace​(java.io.PrintWriter s)
        Overrides:
        printStackTrace in class java.lang.Throwable
      • printStackTrace

        private void printStackTrace​(CompositeException.PrintStreamOrWriter s)
        Special handling for printing out a CompositeException. 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 of e. If e.getCause() returns or e, just return e itself.
        Parameters:
        e - the Throwable e.
        Returns:
        The root cause of e. If e.getCause() returns or e, just return e itself.