Package net.bytebuddy.implementation
Class ExceptionMethod
- java.lang.Object
-
- net.bytebuddy.implementation.ExceptionMethod
-
- All Implemented Interfaces:
InstrumentedType.Prepareable
,ByteCodeAppender
,Implementation
public class ExceptionMethod extends java.lang.Object implements Implementation, ByteCodeAppender
This implementation causes aThrowable
to be thrown when the instrumented method is invoked. Be aware that the Java Virtual machine does not care about exception declarations and will throw anyThrowable
from any method even if the method does not declared a checked exception.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ExceptionMethod.ConstructionDelegate
A construction delegate is responsible for calling a Throwable's constructor.-
Nested classes/interfaces inherited from interface net.bytebuddy.implementation.bytecode.ByteCodeAppender
ByteCodeAppender.Compound, ByteCodeAppender.Simple, ByteCodeAppender.Size
-
Nested classes/interfaces inherited from interface net.bytebuddy.implementation.Implementation
Implementation.Composable, Implementation.Compound, Implementation.Context, Implementation.Simple, Implementation.SpecialMethodInvocation, Implementation.Target
-
-
Constructor Summary
Constructors Constructor Description ExceptionMethod(TypeDescription throwableType, ExceptionMethod.ConstructionDelegate constructionDelegate)
Creates a new instance of an implementation for throwing throwables.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ByteCodeAppender
appender(Implementation.Target implementationTarget)
Creates a byte code appender that determines the implementation of the instrumented type's methods.ByteCodeAppender.Size
apply(org.objectweb.asm.MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod)
Applies this byte code appender to a type creation process.InstrumentedType
prepare(InstrumentedType instrumentedType)
Prepares a given instrumented type.static Implementation
throwing(java.lang.Class<? extends java.lang.Throwable> exceptionType)
Creates an implementation that creates a new instance of the given isThrowable type on each method invocation which is then thrown immediately.static Implementation
throwing(java.lang.Class<? extends java.lang.Throwable> exceptionType, java.lang.String message)
Creates an implementation that creates a new instance of the given isThrowable type on each method invocation which is then thrown immediately.static Implementation
throwing(TypeDescription exceptionType)
Creates an implementation that creates a new instance of the given isThrowable type on each method invocation which is then thrown immediately.static Implementation
throwing(TypeDescription exceptionType, java.lang.String message)
Creates an implementation that creates a new instance of the given isThrowable type on each method invocation which is then thrown immediately.
-
-
-
Constructor Detail
-
ExceptionMethod
public ExceptionMethod(TypeDescription throwableType, ExceptionMethod.ConstructionDelegate constructionDelegate)
Creates a new instance of an implementation for throwing throwables.- Parameters:
throwableType
- The type of the exception to be thrown.constructionDelegate
- A delegate that is responsible for calling the isThrowable's constructor.
-
-
Method Detail
-
throwing
public static Implementation throwing(java.lang.Class<? extends java.lang.Throwable> exceptionType)
Creates an implementation that creates a new instance of the given isThrowable 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:
exceptionType
- The type of the isThrowable.- Returns:
- An implementation that will throw an instance of the isThrowable on each method invocation of the instrumented methods.
-
throwing
public static Implementation throwing(TypeDescription exceptionType)
Creates an implementation that creates a new instance of the given isThrowable 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:
exceptionType
- The type of the isThrowable.- Returns:
- An implementation that will throw an instance of the isThrowable on each method invocation of the instrumented methods.
-
throwing
public static Implementation throwing(java.lang.Class<? extends java.lang.Throwable> exceptionType, java.lang.String message)
Creates an implementation that creates a new instance of the given isThrowable 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 singleString
as its argument.- Parameters:
exceptionType
- The type of the isThrowable.message
- The string that is handed to the constructor. Usually an exception message.- Returns:
- An implementation that will throw an instance of the isThrowable on each method invocation of the instrumented methods.
-
throwing
public static Implementation throwing(TypeDescription exceptionType, java.lang.String message)
Creates an implementation that creates a new instance of the given isThrowable 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 singleString
as its argument.- Parameters:
exceptionType
- The type of the isThrowable.message
- The string that is handed to the constructor. Usually an exception message.- Returns:
- An implementation that will throw an instance of the isThrowable on each method invocation of the instrumented methods.
-
prepare
public InstrumentedType prepare(InstrumentedType instrumentedType)
Description copied from interface:InstrumentedType.Prepareable
Prepares a given instrumented type.- Specified by:
prepare
in interfaceInstrumentedType.Prepareable
- Parameters:
instrumentedType
- The instrumented type in its current form.- Returns:
- The prepared instrumented type.
-
appender
public ByteCodeAppender appender(Implementation.Target implementationTarget)
Description copied from interface:Implementation
Creates a byte code appender that determines the implementation of the instrumented type's methods.- Specified by:
appender
in interfaceImplementation
- 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)
Description copied from interface:ByteCodeAppender
Applies this byte code appender to a type creation process.- Specified by:
apply
in interfaceByteCodeAppender
- 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.
-
-