Class AnchorCombinableException
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
BeanMisconfiguredXMLException
,LocalisedBeanException
,NamedProviderGetException
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 Summary
ConstructorsModifierConstructorDescriptionprotected
AnchorCombinableException
(String description, Throwable cause) Creates with a description and a cause. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract boolean
canExceptionBeCombined
(Throwable exception) Can another exception be combined with this exception?protected abstract boolean
canExceptionBeSkipped
(Throwable exception) Can another exception be skipped, when we combine with the current exception?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.protected abstract String
createMessageForDescription
(String description) Creates a message for the exception from the description.protected Throwable
Traverses through the nested-exceptions and finds the most deep exception that is combinable.The (uncombined) description associated with the exception.protected boolean
Are there nested-exceptions (according to our traversal rules) that are combinable?abstract Throwable
Creates a new {link Throwable} that summarizes this exception and any nested causes of the exception.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
AnchorCombinableException
Creates with a description and a cause.- Parameters:
description
- the description.cause
- the cause.
-
-
Method Details
-
canExceptionBeCombined
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
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
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
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
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 initiallyseperator
- a separator is placed between the description of each exception- Returns:
- a string as above
-
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
The (uncombined) description associated with the exception.
-