Class 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: 2015-04-20 11:08:18 +0200 (må, 20 apr 2015) $
    • 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