Class MultipleCauses

  • All Implemented Interfaces:
    java.io.Serializable

    public class MultipleCauses
    extends java.lang.Throwable
    Use an instance of this class as the cause when you need to record several causes of an exception. This paradigm would be necessary when multiple attempts can be made to complete a task, e.g., traversing a list of plugins until one can handle a given condition. If all attempts fail, it is desirable to report on each attempt. This class acts as a wrapper allowing multiple causes to be recorded in place of one. The causes recorded in this wrapper actually apply to the throwable ("parent") which has this MultipleCauses exception as its cause.
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  MultipleCauses.Util  
    • Constructor Summary

      Constructors 
      Constructor Description
      MultipleCauses()
      Constructs a new MultipleCauses wrapper with no causes NOTE: it is rude to leave this empty
      MultipleCauses​(java.util.Collection<java.lang.Throwable> causes)
      Constructs a new MultipleCauses wrapper with the given causes
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addAllCauses​(MultipleCauses that)
      Add the causes from another MultipleCauses into this one
      void addAllCauses​(java.lang.Throwable e)
      Assuming a throwable has multiple causes, add them all to this MultipleCauses
      void addCause​(java.lang.Throwable cause)
      Add the cause to the collection of causes (for the "parent" throwable)
      void addFlattenedIfMultiple​(java.lang.Throwable e)
      If the throwable has multiple causes, collect its causes into this MultipleCauses.
      java.lang.Throwable getCause()
      Use getCauses instead
      java.util.Collection<java.lang.Throwable> getCauses()
      Returns the causes of the parent throwable (possibly an empty collection)
      static boolean hasMultiple​(java.lang.Throwable e)  
      java.lang.Throwable initCause​(java.lang.Throwable cause)
      Use addCause instead
      boolean isEmpty()  
      static void printTree​(java.io.PrintStream out, java.lang.String prefix, java.lang.Throwable e)  
      static void printTree​(java.io.PrintStream out, java.lang.Throwable e)  
      • Methods inherited from class java.lang.Throwable

        addSuppressed, fillInStackTrace, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • MultipleCauses

        public MultipleCauses()
        Constructs a new MultipleCauses wrapper with no causes NOTE: it is rude to leave this empty
      • MultipleCauses

        public MultipleCauses​(java.util.Collection<java.lang.Throwable> causes)
        Constructs a new MultipleCauses wrapper with the given causes
        Parameters:
        causes -
    • Method Detail

      • getCause

        public java.lang.Throwable getCause()
        Use getCauses instead
        Overrides:
        getCause in class java.lang.Throwable
        Returns:
        null
      • getCauses

        public java.util.Collection<java.lang.Throwable> getCauses()
        Returns the causes of the parent throwable (possibly an empty collection)
        Returns:
        the collection of causes of the parent throwable NOTE: it is rude to leave this empty. If the parent throwable has no cause, or the cause is unknown, leave its cause null.
      • addCause

        public void addCause​(java.lang.Throwable cause)
        Add the cause to the collection of causes (for the "parent" throwable)
        Parameters:
        cause - the throwable to add as a cause
      • addFlattenedIfMultiple

        public void addFlattenedIfMultiple​(java.lang.Throwable e)
        If the throwable has multiple causes, collect its causes into this MultipleCauses. Otherwise, just add it as a cause.
        Parameters:
        e -
      • addAllCauses

        public void addAllCauses​(java.lang.Throwable e)
        Assuming a throwable has multiple causes, add them all to this MultipleCauses
        Parameters:
        e - the throwable having multiple causes This is useful for flattening causes into a common exception. For instance, if a method is collecting multiple causes for a potential WidgetException, and it catches a WidgetException, instead of collecting the caught WidgetException, it might instead copy its causes into its own collection.
      • addAllCauses

        public void addAllCauses​(MultipleCauses that)
        Add the causes from another MultipleCauses into this one
        Parameters:
        that - the source to copy from
      • initCause

        public java.lang.Throwable initCause​(java.lang.Throwable cause)
        Use addCause instead
        Overrides:
        initCause in class java.lang.Throwable
      • isEmpty

        public boolean isEmpty()
      • hasMultiple

        public static boolean hasMultiple​(java.lang.Throwable e)
      • printTree

        public static void printTree​(java.io.PrintStream out,
                                     java.lang.Throwable e)
      • printTree

        public static void printTree​(java.io.PrintStream out,
                                     java.lang.String prefix,
                                     java.lang.Throwable e)