Class MultipleCauses

java.lang.Object
java.lang.Throwable
ghidra.util.exception.MultipleCauses
All Implemented Interfaces:
Serializable

public class MultipleCauses extends 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:
  • Constructor Details

    • MultipleCauses

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

      public MultipleCauses(Collection<Throwable> causes)
      Constructs a new MultipleCauses wrapper with the given causes
      Parameters:
      causes -
  • Method Details

    • getCause

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

      public Collection<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(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(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(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 Throwable initCause(Throwable cause)
      Use addCause instead
      Overrides:
      initCause in class Throwable
    • isEmpty

      public boolean isEmpty()
    • hasMultiple

      public static boolean hasMultiple(Throwable e)
    • printTree

      public static void printTree(PrintStream out, Throwable e)
    • printTree

      public static void printTree(PrintStream out, String prefix, Throwable e)