public abstract class AnchorCombinableException extends AnchorCheckedException
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.
Modifier | Constructor and Description |
---|---|
protected |
AnchorCombinableException(String description,
Throwable cause)
Creates with a description and a cause.
|
Modifier and Type | Method and Description |
---|---|
protected 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 |
findMostDeepCombinableException()
Traverses through the nested-exceptions and finds the most deep exception that is combinable.
|
String |
getDescription()
The (uncombined) description associated with the exception.
|
protected boolean |
hasNoCombinableNestedExceptions()
Are there nested-exceptions (according to our traversal rules) that are combinable?
|
abstract Throwable |
summarize()
Creates a new {link Throwable} that summarizes this exception and any nested causes of the
exception.
|
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
protected abstract boolean canExceptionBeCombined(Throwable exception)
exception
- the other exception to check if it can be combined.protected abstract boolean canExceptionBeSkipped(Throwable exception)
exception
- the other exception to check if it can be skipped.public abstract Throwable summarize()
This can effectively combine a chain of nested exceptions into a single exception without a cause.
protected abstract String createMessageForDescription(String description)
description
- either a single description, or a combined descriptionprotected Throwable combineDescriptionsRecursively(String prefix, String seperator)
prefix
- a string to be inserted initiallyseperator
- a separator is placed between the description of each exceptionprotected Throwable findMostDeepCombinableException()
This determination uses the rules about combining and skipping outlined in the class description.
protected boolean hasNoCombinableNestedExceptions()
public String getDescription()
Copyright © 2010–2023 Owen Feehan, ETH Zurich, University of Zurich, Hoffmann-La Roche. All rights reserved.