2.17.2: 2011-06-17

net.sf.basedb.util.error
Class ClassMapErrorHandler

java.lang.Object
  extended by 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 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: 2008-09-11 22:08:14 +0200 (Thu, 11 Sep 2008) $

Field Summary
private  ErrorHandler defaultErrorHandler
           
private  Map<Class<? extends Throwable>,List<ErrorHandler>> errorHandlers
          Map of registered error handlers.
 
Constructor Summary
ClassMapErrorHandler(ErrorHandler defaultErrorHandler)
          Create a new ClassMapErrorHandler.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 new ClassMapErrorHandler.

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 handle
handler - 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 operation 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.

Specified by:
handleError in interface ErrorHandler
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

2.17.2: 2011-06-17