Class ExceptionMapper<X extends Exception>

  • Type Parameters:
    X - the exception type
    All Implemented Interfaces:
    Function<Exception,​X>, Function<Exception,​X>
    Direct Known Subclasses:
    ReflectiveExceptionMapper

    public abstract class ExceptionMapper<X extends Exception>
    extends Object
    implements Function<Exception,​X>
    Utility exception mapper which translates an Exception to a specified type of Exception. This mapper is intended to be primarily used with com.google.common.util.concurrent.Futures.makeChecked()
    • if exception is the specified type or one of its subclasses, it returns original exception.
    • if exception is ExecutionException and the cause is of the specified type, it returns the cause
    • otherwise returns an instance of the specified exception type with original exception as the cause.
    Author:
    Thomas Pantelis
    • Constructor Detail

      • ExceptionMapper

        public ExceptionMapper​(String opName,
                               Class<X> exceptionType)
        Constructor.
        Parameters:
        opName - the String prefix for exception messages.
        exceptionType - the exception type to which to translate.
    • Method Detail

      • getExceptionType

        protected final Class<X> getExceptionType()
        Return the exception class produced by this instance.
        Returns:
        Exception class.
      • newWithCause

        protected abstract X newWithCause​(String message,
                                          Throwable cause)
        Invoked to create a new exception instance of the specified type.
        Parameters:
        message - the message for the new exception.
        cause - the cause for the new exception.
        Returns:
        an instance of the exception type.