Class ReflectiveExceptionMapper<X extends Exception>

java.lang.Object
org.opendaylight.yangtools.util.concurrent.ExceptionMapper<X>
org.opendaylight.yangtools.util.concurrent.ReflectiveExceptionMapper<X>
Type Parameters:
X - Exception type
All Implemented Interfaces:
Function<Exception,X>, Function<Exception,X>

public final class ReflectiveExceptionMapper<X extends Exception> extends ExceptionMapper<X>
Convenience ExceptionMapper which instantiates specified Exception using reflection. The Exception types are expected to declare an accessible constructor which takes two arguments: a String and a Throwable.
  • Method Details

    • newWithCause

      protected X newWithCause(String message, Throwable cause)
      Description copied from class: ExceptionMapper
      Invoked to create a new exception instance of the specified type.
      Specified by:
      newWithCause in class ExceptionMapper<X extends Exception>
      Parameters:
      message - the message for the new exception.
      cause - the cause for the new exception.
      Returns:
      an instance of the exception type.
    • create

      public static <X extends Exception> ReflectiveExceptionMapper<X> create(String opName, Class<X> exceptionType)
      Create a new instance of the reflective exception mapper. This method performs basic sanity checking on the exception class. This method is potentially very costly, so users are strongly encouraged to cache the returned mapper for reuse.
      Parameters:
      opName - Operation performed
      exceptionType - Exception type
      Returns:
      A new mapper instance
      Throws:
      IllegalArgumentException - when the supplied exception class does not pass sanity checks
      SecurityException - when the required constructor is not accessible