Class ExceptionMatcher
java.lang.Object
org.springframework.kafka.support.ExceptionMatcher
Configurable exception matcher with support for identifying matching exception in
nested causes. The matcher can be configured in two ways:
- With an allow list, only the registered exception matches. This includes exceptions that extend from any registered exception or implement it if that's an interface.
- With a () deny list, an exception match only if it isn't found amongst the registered exceptions. As for the allowlist, any exception that extends or implements one of the registered exceptions will lead it to not match.
Throwable
is inspected. To also search nested
causes, traverseCauses
should be enabled.- Since:
- 4.0
- Author:
- Stephane Nicoll, Dave Syer, Gary Russell
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsModifierConstructorDescriptionExceptionMatcher
(Collection<Class<? extends Throwable>> exceptionTypes, boolean shouldMatchIfFound) Create an instance with a list of exceptions.protected
ExceptionMatcher
(Map<Class<? extends Throwable>, Boolean> entries, boolean matchIfNotFound, boolean traverseCauses) -
Method Summary
Modifier and TypeMethodDescriptionstatic ExceptionMatcher
Create a matcher that matches anyException
, but not errors.static ExceptionMatcher.Builder
Create a builder for a matcher that only matches an exception that is found in the configurable list of exception types.static ExceptionMatcher.Builder
Create a builder for a matcher that only matches an exception that is not found in the configurable list of exception types.boolean
Specify if the givenThrowable
match this instance.void
setTraverseCauses
(boolean traverseCauses) Specify if this match should traverse nested causes to check for the presence of a matching exception.
-
Constructor Details
-
ExceptionMatcher
public ExceptionMatcher(Collection<Class<? extends Throwable>> exceptionTypes, boolean shouldMatchIfFound) Create an instance with a list of exceptions. TheshouldMatchIfFound
parameter determines what should happen if an exception is found within that list.- Parameters:
exceptionTypes
- the exceptions to registershouldMatchIfFound
- match result if a candidate exception is found amongst the given list
-
ExceptionMatcher
-
-
Method Details
-
defaultMatcher
Create a matcher that matches anyException
, but not errors.- Returns:
- a matcher that matches any exception, but not errors
-
forAllowList
Create a builder for a matcher that only matches an exception that is found in the configurable list of exception types.- Returns:
- a
ExceptionMatcher.Builder
that configures an allowlist of exceptions
-
forDenyList
Create a builder for a matcher that only matches an exception that is not found in the configurable list of exception types.- Returns:
- a
ExceptionMatcher.Builder
that configures a denylist of exceptions
-
setTraverseCauses
public void setTraverseCauses(boolean traverseCauses) Specify if this match should traverse nested causes to check for the presence of a matching exception.- Parameters:
traverseCauses
- whether to traverse causes
-
match
-
getEntries
-