@HashCodeAndEqualsPlugin.Enhance public class ExceptionMethod extends java.lang.Object implements Implementation, ByteCodeAppender
Throwable
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 any
Throwable
from any method even if the method does not declared a checked exception.Modifier and Type | Class and Description |
---|---|
static interface |
ExceptionMethod.ConstructionDelegate
A construction delegate is responsible for calling a
Throwable 's constructor. |
Implementation.Composable, Implementation.Compound, Implementation.Context, Implementation.Simple, Implementation.SpecialMethodInvocation, Implementation.Target
ByteCodeAppender.Compound, ByteCodeAppender.Simple, ByteCodeAppender.Size
Modifier and Type | Field and Description |
---|---|
private ExceptionMethod.ConstructionDelegate |
constructionDelegate
The construction delegation which is responsible for creating the exception to be thrown.
|
Constructor and Description |
---|
ExceptionMethod(ExceptionMethod.ConstructionDelegate constructionDelegate)
Creates a new instance of an implementation for throwing throwables.
|
Modifier and Type | Method and 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> throwableType)
Creates an implementation that creates a new instance of the given
Throwable type on each method invocation
which is then thrown immediately. |
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. |
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. |
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. |
private final ExceptionMethod.ConstructionDelegate constructionDelegate
public ExceptionMethod(ExceptionMethod.ConstructionDelegate constructionDelegate)
constructionDelegate
- A delegate that is responsible for calling the Throwable
's constructor.public static Implementation throwing(java.lang.Class<? extends java.lang.Throwable> throwableType)
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.throwableType
- The type of the Throwable
.Throwable
on each method invocation of the
instrumented methods.public static Implementation throwing(TypeDescription throwableType)
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.throwableType
- The type of the Throwable
.Throwable
on each method invocation of the
instrumented methods.public static Implementation throwing(java.lang.Class<? extends java.lang.Throwable> throwableType, java.lang.String message)
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.throwableType
- The type of the Throwable
.message
- The string that is handed to the constructor. Usually an exception message.Throwable
on each method invocation
of the instrumented methods.public static Implementation throwing(TypeDescription throwableType, java.lang.String message)
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.throwableType
- The type of the Throwable
.message
- The string that is handed to the constructor. Usually an exception message.Throwable
on each method invocation
of the instrumented methods.public InstrumentedType prepare(InstrumentedType instrumentedType)
prepare
in interface InstrumentedType.Prepareable
instrumentedType
- The instrumented type in its current form.public ByteCodeAppender appender(Implementation.Target implementationTarget)
appender
in interface Implementation
implementationTarget
- The target of the current implementation.InstrumentedType.Prepareable.prepare(InstrumentedType)
.public ByteCodeAppender.Size apply(org.objectweb.asm.MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod)
apply
in interface ByteCodeAppender
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.