Class ExceptionMethod

    • Field Detail

      • constructionDelegate

        private final ExceptionMethod.ConstructionDelegate constructionDelegate
        The construction delegation which is responsible for creating the exception to be thrown.
    • Constructor Detail

      • ExceptionMethod

        public ExceptionMethod​(ExceptionMethod.ConstructionDelegate constructionDelegate)
        Creates a new instance of an implementation for throwing throwables.
        Parameters:
        constructionDelegate - A delegate that is responsible for calling the Throwable's constructor.
    • Method Detail

      • throwing

        public static Implementation throwing​(java.lang.Class<? extends java.lang.Throwable> throwableType)
        Creates an implementation that creates a new instance of the given Throwable type on each method invocation which is then thrown immediately. For this to be possible, the given type must define a default constructor which is visible from the instrumented type.
        Parameters:
        throwableType - The type of the Throwable.
        Returns:
        An implementation that will throw an instance of the Throwable on each method invocation of the instrumented methods.
      • throwing

        public static Implementation throwing​(TypeDescription throwableType)
        Creates an implementation that creates a new instance of the given Throwable type on each method invocation which is then thrown immediately. For this to be possible, the given type must define a default constructor which is visible from the instrumented type.
        Parameters:
        throwableType - The type of the Throwable.
        Returns:
        An implementation that will throw an instance of the Throwable on each method invocation of the instrumented methods.
      • throwing

        public static Implementation throwing​(java.lang.Class<? extends java.lang.Throwable> throwableType,
                                              java.lang.String message)
        Creates an implementation that creates a new instance of the given Throwable type on each method invocation which is then thrown immediately. For this to be possible, the given type must define a constructor that takes a single String as its argument.
        Parameters:
        throwableType - The type of the Throwable.
        message - The string that is handed to the constructor. Usually an exception message.
        Returns:
        An implementation that will throw an instance of the Throwable on each method invocation of the instrumented methods.
      • throwing

        public static Implementation throwing​(TypeDescription throwableType,
                                              java.lang.String message)
        Creates an implementation that creates a new instance of the given Throwable type on each method invocation which is then thrown immediately. For this to be possible, the given type must define a constructor that takes a single String as its argument.
        Parameters:
        throwableType - The type of the Throwable.
        message - The string that is handed to the constructor. Usually an exception message.
        Returns:
        An implementation that will throw an instance of the Throwable on each method invocation of the instrumented methods.
      • appender

        public ByteCodeAppender appender​(Implementation.Target implementationTarget)
        Creates a byte code appender that determines the implementation of the instrumented type's methods.
        Specified by:
        appender in interface Implementation
        Parameters:
        implementationTarget - The target of the current implementation.
        Returns:
        A byte code appender for implementing methods delegated to this implementation. This byte code appender is also responsible for handling methods that were added by this implementation on the call to InstrumentedType.Prepareable.prepare(InstrumentedType).
      • apply

        public ByteCodeAppender.Size apply​(org.objectweb.asm.MethodVisitor methodVisitor,
                                           Implementation.Context implementationContext,
                                           MethodDescription instrumentedMethod)
        Applies this byte code appender to a type creation process.
        Specified by:
        apply in interface ByteCodeAppender
        Parameters:
        methodVisitor - The method visitor to which the byte code appender writes its code to.
        implementationContext - The implementation context of the current type creation process.
        instrumentedMethod - The method that is the target of the instrumentation.
        Returns:
        The required size for the applied byte code to run.