public class ClassMapErrorHandler extends 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 Map<Class<? extends Throwable>,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(Class<? extends Throwable> t,
ErrorHandler handler)
Add an error handler for throwable:s of a specific class.
|
boolean |
handleError(Throwable t)
Handle an error.
|
private Map<Class<? extends Throwable>,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(Class<? extends Throwable> t, ErrorHandler handler)
t
- The class of throwable:s the error handler should handlehandler
- The error handlerpublic boolean handleError(Throwable t) throws 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 handleThrowable
- If the error is final and can't be solved