Class AnchorCombinableException

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
BeanMisconfiguredXMLException, LocalisedBeanException, NamedProviderGetException

public abstract class AnchorCombinableException extends AnchorCheckedException
An exception that can be combined with similar exceptions and summarized.

A special type of exception where lots of nested exceptions of the same type can be combined together to create a new exception summarizing them all together.

This is useful for nested-exceptions which could be better expressed as a path e.g. /cause3/cause2/cause1/exception

It is also supported to skip certain exception types when traversing through the hierarchy of nested exceptions (i.e. getCause().getCause().getCause().

When skipped, the exception is ignored, and its getCause() is then processed.

Otherwise, if a getCause() is encountered that can be neither combined, nor skipped, the process ends.

Finally, a SummaryException is created representing the combined beans. Its getCause() is set as the getCause() of the last bean to be combined.

Author:
Owen Feehan
See Also:
  • Constructor Details

    • AnchorCombinableException

      protected AnchorCombinableException(String description, Throwable cause)
      Creates with a description and a cause.
      Parameters:
      description - the description.
      cause - the cause.
  • Method Details

    • canExceptionBeCombined

      protected abstract boolean canExceptionBeCombined(Throwable exception)
      Can another exception be combined with this exception?
      Parameters:
      exception - the other exception to check if it can be combined.
      Returns:
      true iff this exception is compatible to be combined with the current exception.
    • canExceptionBeSkipped

      protected abstract boolean canExceptionBeSkipped(Throwable exception)
      Can another exception be skipped, when we combine with the current exception?
      Parameters:
      exception - the other exception to check if it can be skipped.
      Returns:
      true iff this exception is compatible to be skipped, when processing the current exception.
    • summarize

      public abstract Throwable summarize()
      Creates a new {link Throwable} that summarizes this exception and any nested causes of the exception.

      This can effectively combine a chain of nested exceptions into a single exception without a cause.

      Returns:
      an exception summarizing the current exception, and any causes.
    • createMessageForDescription

      protected abstract String createMessageForDescription(String description)
      Creates a message for the exception from the description.
      Parameters:
      description - either a single description, or a combined description
      Returns:
      a message describing an error, incorporating description
    • combineDescriptionsRecursively

      protected Throwable combineDescriptionsRecursively(String prefix, String seperator)
      Traverses through a set of nested-exceptions creating a description for each "combined" exception, and combining them into a single string.
      Parameters:
      prefix - a string to be inserted initially
      seperator - a separator is placed between the description of each exception
      Returns:
      a string as above
    • findMostDeepCombinableException

      protected Throwable findMostDeepCombinableException()
      Traverses through the nested-exceptions and finds the most deep exception that is combinable.

      This determination uses the rules about combining and skipping outlined in the class description.

      Returns:
      the depth-most exception that is found by this search
    • hasNoCombinableNestedExceptions

      protected boolean hasNoCombinableNestedExceptions()
      Are there nested-exceptions (according to our traversal rules) that are combinable?
      Returns:
      true if there are, false otherwise.
    • getDescription

      public String getDescription()
      The (uncombined) description associated with the exception.