T - The subtype bound of exception to allow exception handlers for.R - The result type that will be produced by these error handlers.public class HashedErrorHandler<T extends Throwable,R> extends Object implements CycleErrorHandler<T,R>
setUpperBound(Class).
You may also register named groups of exceptions for which you can set the handler in
a single call.
CycleErrorHandler
from which this aggregating handler is built. R can be any type that makes sense
for your particular error handling logic. For example, a Boolean return type can
be used to signal whether down-chain handlers should be executed or not.
Class.getSimpleName() version of the classname. Further,
simple substrings consisting only of word characters are considered shortcuts for
single Throwable types and thus throw an exception if more than one is matched.
Patterns that contain non-word characters allow for bulk management.CycleErrorHandler.Triple<T,R>| Constructor and Description |
|---|
HashedErrorHandler() |
| Modifier and Type | Method and Description |
|---|---|
void |
addValidClasses(Class<? extends T>... validClasses)
Add to the set of valid classes that will be used when searching for a class
by name.
|
Set<Class<? extends T>> |
getGroup(String groupName) |
List<String> |
getGroupNames() |
Map<Class<? extends T>,CycleErrorHandler<T,R>> |
getHandlers()
Return the current list of active handler assignments.
|
Set<Class<? extends T>> |
getValidClasses() |
R |
handleError(long cycle,
T throwable,
String errMsg)
Handle the error according to the matching error handler for the supplied
Throwable subtype. |
void |
resetAllClassHandlers()
Unset all class handlers.
|
HashedErrorHandler<T,R> |
setDefaultHandler(CycleErrorHandler<T,R> errorHandler)
Set the default handler that gets called on any exceptions that do not match a class
or super-class specific handler.
|
void |
setGroup(String groupName,
Class<? extends T>... exceptions)
Set a group name for a set of classes.
|
void |
setHandlerForClasses(CycleErrorHandler<T,R> errorHandler,
Class<? extends T>... errorClasses)
Set the error handler for the specified class, and any subclasses of it.
|
void |
setHandlerForGroup(String groupName,
CycleErrorHandler<T,R> errorHandler)
Set the error handler for a named group of exception classes.
|
void |
setHandlerForPattern(String pattern,
CycleErrorHandler<T,R> errorHandler)
Find the matching classes from the recognized classes, and then
set the handler for all of them.
|
HashedErrorHandler<T,R> |
setUpperBound(Class<? extends T> upperBound)
Sets the uppper bound on the Throwable type that you want to consider when
walking up the class hierarchy to find a handled supertype.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waithandleError, handleError@SafeVarargs public final void setGroup(String groupName, Class<? extends T>... exceptions)
groupName - the name that the group will be referred to asexceptions - the set of exceptions to include in the group@SafeVarargs public final void setHandlerForClasses(CycleErrorHandler<T,R> errorHandler, Class<? extends T>... errorClasses)
errorHandler - The error handler to be called when this class or any subclasses
that do not have their own more specific handler.errorClasses - The set of classes to set the handler forpublic final void setHandlerForGroup(String groupName, CycleErrorHandler<T,R> errorHandler)
errorHandler - The error handler to be called when this class or any
subclasses that do not have their own more specific handler.groupName - The named group of exception classesRuntimeException - if the group name is not foundpublic final void setHandlerForPattern(String pattern, CycleErrorHandler<T,R> errorHandler)
pattern - A substring or regex for the class nameserrorHandler - the error handler to be registered for the classespublic final void resetAllClassHandlers()
public final Map<Class<? extends T>,CycleErrorHandler<T,R>> getHandlers()
Map of Class to CycleErrorHandler.@SafeVarargs public final void addValidClasses(Class<? extends T>... validClasses)
validClasses - The classes that this error handler will searchpublic HashedErrorHandler<T,R> setDefaultHandler(CycleErrorHandler<T,R> errorHandler)
errorHandler - The error handler to be called as a last resort.public HashedErrorHandler<T,R> setUpperBound(Class<? extends T> upperBound)
Throwable. If the set of types that should be
handled directly are more limited than this, you can cause the default handler
to trigger when the upper bound type is found if the traversal gets that far.upperBound - The Throwable subtype which is the lowest subtype to handlepublic R handleError(long cycle, T throwable, String errMsg)
Throwable subtype. Handlers of supertypes are used when a specific
handler is not found for the reported error class. This means that you
can install a default handler for a throwable that is a common parent to
your exceptions and have it handle all reported errors by default.
The return type is contextual to how this handler class is used. If it is important to use error handler implementations to control flow or other optional execution, then the return type can be used as a form of signaling for that. If you have no need for this, then simply use these classes with a Void result type in the R parameter.
handleError in interface CycleErrorHandler<T extends Throwable,R>cycle - The activity cycle for which the error is being handledthrowable - The exception that was thrown or that needs to be handlederrMsg - A detailed message explaining the errorCopyright © 2018. All rights reserved.