Class ExceptionMapper<X extends Exception>

java.lang.Object
org.opendaylight.yangtools.util.concurrent.ExceptionMapper<X>
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 Details

    • 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 Details

    • 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.
    • apply

      public X apply(Exception input)
      Specified by:
      apply in interface Function<Exception,X extends Exception>
      Specified by:
      apply in interface Function<Exception,X extends Exception>