Package net.sf.basedb.util.error
Class ClassMapErrorHandler
java.lang.Object
net.sf.basedb.util.error.ClassMapErrorHandler
- All Implemented Interfaces:
ErrorHandler
Error handler that allows the registration of one or more
error handler for subclasses to
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.
- Version:
- 2.0
- Author:
- nicklas
- Last modified
- $Date: 2015-04-20 11:08:18 +0200 (må, 20 apr 2015) $
-
Field Summary
Modifier and TypeFieldDescriptionprivate final ErrorHandler
private Map<Class<? extends Throwable>,
List<ErrorHandler>> Map of registered error handlers. -
Constructor Summary
ConstructorDescriptionClassMapErrorHandler
(ErrorHandler defaultErrorHandler) Create a newClassMapErrorHandler
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addErrorHandler
(Class<? extends Throwable> t, ErrorHandler handler) Add an error handler for throwable:s of a specific class.boolean
Handle an error.
-
Field Details
-
errorHandlers
Map of registered error handlers. -
defaultErrorHandler
-
-
Constructor Details
-
ClassMapErrorHandler
Create a newClassMapErrorHandler
.- Parameters:
defaultErrorHandler
- The default error handler to use if no other error handler is found, if null the error is re-thrown
-
-
Method Details
-
addErrorHandler
Add an error handler for throwable:s of a specific class. The error handler will also handle errors of all subclasses unless a specific error handler exists for that subclass.- Parameters:
t
- The class of throwable:s the error handler should handlehandler
- The error handler
-
handleError
Description copied from interface:ErrorHandler
Handle an error. If it is decided that the error is a final error this method should rethrow the same or a different exception. If if is decided that it is possible to continue with the current operationtrue
should be returned. Iffalse
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.- Specified by:
handleError
in interfaceErrorHandler
- Parameters:
t
- The error to handle- Returns:
- TRUE if the error was handled successfully and the execution should continue with the next item
- Throws:
Throwable
- If the error is final and can't be solved
-