@Retention(CLASS) @Target(METHOD) @Documented public @interface Signature
Throwable
return type.
Given the following exception and message bundle interface method the InvalidIntValueException(final RuntimeException cause, final String msg, final int value)
constructor would be used.
public class InvalidIntValueException extends RuntimeException {
private final RuntimeException causeAsRuntime;
private final int value;
public InvalidIntValueException(final Throwable cause, final String msg, final int value) {
super(msg, cause);
causeAsRuntime = new RuntimeException(cause);
this.value = value;
}
public InvalidIntValueException(final RuntimeException cause, final String msg, final int value) {
super(msg, cause);
causeAsRuntime = cause;
this.value = value;
}
public InvalidIntValueException(final RuntimeException cause, final String msg, final Integer value) {
super(msg, cause);
causeAsRuntime = cause;
this.value = value;
}
}
@Message("Invalid value %d")
@Signature(causeIndex = 0, messageIndex = 1, value = {RuntimeException.class, String.class, int.class}
InvalidIntValueException invalidValue(@Cause RuntimeException cause, @Param int value);
Modifier and Type | Required Element | Description |
---|---|---|
Class<?>[] |
value |
An array of types matching the exact signature to use for the exception being created.
|
Modifier and Type | Optional Element | Description |
---|---|---|
int |
causeIndex |
The index for the cause of the exception being created.
|
int |
messageIndex |
The index for the message.
|
Class<?>[] value
int causeIndex
Cause
annotation can still be used and the
Throwable.initCause(Throwable)
will be used to initialize the cause of the exception.int messageIndex
Message.value()
. This is a required
value defaulting to 0 which would be the first parameter.Copyright © 2018. All rights reserved.