Package net.sf.basedb.util.error
Class ClassMapErrorHandler
- java.lang.Object
-
- net.sf.basedb.util.error.ClassMapErrorHandler
-
- All Implemented Interfaces:
ErrorHandler
public class ClassMapErrorHandler extends Object implements ErrorHandler
Error handler that allows the registration of one or more error handler for subclasses toThrowable
.Use the
addErrorHandler(Class, ErrorHandler)
to register error handlers for specific exceptions. When thehandleError(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
Fields Modifier and Type Field Description private ErrorHandler
defaultErrorHandler
private Map<Class<? extends Throwable>,List<ErrorHandler>>
errorHandlers
Map of registered error handlers.
-
Constructor Summary
Constructors Constructor Description ClassMapErrorHandler(ErrorHandler defaultErrorHandler)
Create a newClassMapErrorHandler
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Field Detail
-
errorHandlers
private Map<Class<? extends Throwable>,List<ErrorHandler>> errorHandlers
Map of registered error handlers.
-
defaultErrorHandler
private final ErrorHandler defaultErrorHandler
-
-
Constructor Detail
-
ClassMapErrorHandler
public ClassMapErrorHandler(ErrorHandler defaultErrorHandler)
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 Detail
-
addErrorHandler
public void addErrorHandler(Class<? extends Throwable> t, ErrorHandler handler)
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
public boolean handleError(Throwable t) throws Throwable
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
-
-