public class ClassMapErrorHandler extends java.lang.Object implements ErrorHandler
Throwable
.
Use the addErrorHandler(Class, ErrorHandler)
to register
error handlers for specific exceptions. When the handleError(Throwable)
is invoked it checks the class of the throwable and looks for error handlers
for that class. If it can't find an error handler it will check the superclass
and so on. If no error handler is found the orginal error is re-thrown.
Modifier and Type | Field and Description |
---|---|
private ErrorHandler |
defaultErrorHandler |
private java.util.Map<java.lang.Class<? extends java.lang.Throwable>,java.util.List<ErrorHandler>> |
errorHandlers
Map of registered error handlers.
|
Constructor and Description |
---|
ClassMapErrorHandler(ErrorHandler defaultErrorHandler)
Create a new
ClassMapErrorHandler . |
Modifier and Type | Method and Description |
---|---|
void |
addErrorHandler(java.lang.Class<? extends java.lang.Throwable> t,
ErrorHandler handler)
Add an error handler for throwable:s of a specific class.
|
boolean |
handleError(java.lang.Throwable t)
Handle an error.
|
private java.util.Map<java.lang.Class<? extends java.lang.Throwable>,java.util.List<ErrorHandler>> errorHandlers
private final ErrorHandler defaultErrorHandler
public ClassMapErrorHandler(ErrorHandler defaultErrorHandler)
ClassMapErrorHandler
.defaultErrorHandler
- The default error handler to use if no
other error handler is found, if null the error is re-thrownpublic void addErrorHandler(java.lang.Class<? extends java.lang.Throwable> t, ErrorHandler handler)
t
- The class of throwable:s the error handler should handlehandler
- The error handlerpublic boolean handleError(java.lang.Throwable t) throws java.lang.Throwable
ErrorHandler
true
should be returned. If false
is returned
it indicates that this error handled doesn't know how to handle the
error. The caller should try another error handler or throw an exception.handleError
in interface ErrorHandler
t
- The error to handlejava.lang.Throwable
- If the error is final and can't be solved