spring-projects/spring-framework · error · IllegalStateException
Throwing argument name '{}' was not bound in advice argument
Error message
Throwing argument name '{}' was not bound in advice arguments What it means
Thrown by bindExplicitArguments (line 497-501) when throwingName is set but is not a key in argumentBindings, i.e. no advice parameter carries that name. Spring needs a Throwable parameter with that name to bind the thrown exception.
Source
Thrown at spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java:499
this.argumentBindings.put(this.argumentNames[i], i);
}
// Check that returning and throwing were in the argument names list if
// specified, and find the discovered argument types.
if (this.returningName != null) {
if (!this.argumentBindings.containsKey(this.returningName)) {
throw new IllegalStateException("Returning argument name '" + this.returningName +
"' was not bound in advice arguments");
}
else {
Integer index = this.argumentBindings.get(this.returningName);
this.discoveredReturningType = this.aspectJAdviceMethod.getParameterTypes()[index];
this.discoveredReturningGenericType = this.aspectJAdviceMethod.getGenericParameterTypes()[index];
}
}
if (this.throwingName != null) {
if (!this.argumentBindings.containsKey(this.throwingName)) {
throw new IllegalStateException("Throwing argument name '" + this.throwingName +
"' was not bound in advice arguments");
}
else {
Integer index = this.argumentBindings.get(this.throwingName);
this.discoveredThrowingType = this.aspectJAdviceMethod.getParameterTypes()[index];
}
}
// configure the pointcut expression accordingly.
configurePointcutParameters(this.argumentNames, argumentIndexOffset);
}
/**
* All parameters from argumentIndexOffset onwards are candidates for
* pointcut parameters - but returning and throwing vars are handled differently
* and must be removed from the list if present.
*/
private void configurePointcutParameters(String[] argumentNames, int argumentIndexOffset) {View on GitHub (pinned to e8729d0438)
Solutions
- Make the 'throwing' value exactly match the name of a Throwable advice parameter (and include it in arg-names if supplied).
- Add the missing Throwable parameter to the advice method so the throwing name binds.
- Compile with -parameters or specify arg-names consistently so names line up.
- If you do not need to bind the exception, remove the throwing attribute.
Example fix
// before
@AfterThrowing(value = "...", throwing = "ex")
public void onThrow(RuntimeException error) { ... }
// after
@AfterThrowing(value = "...", throwing = "ex")
public void onThrow(RuntimeException ex) { ... } Defensive patterns
Strategy: validation
Validate before calling
// Ensure the throwing name corresponds to an actual parameter name.
Set<String> paramNames = Set.of(new DefaultParameterNameDiscoverer().getParameterNames(adviceMethod));
if (throwingName != null && !paramNames.contains(throwingName)) {
throw new IllegalStateException(
"throwing='" + throwingName + "' is not among advice parameters " + paramNames);
} Prevention
- Keep the throwing attribute value identical to the bound exception parameter name.
- Rename the throwing attribute whenever you rename the parameter.
- Compile with -parameters so names are reliably available.
When it happens
Trigger: The 'throwing' attribute names a value that is not among the advice method's parameter names (or arg-names). E.g. throwing="ex" but the advice parameter is named 'error', or the parameter was omitted.
Common situations: Renaming the exception parameter without updating the throwing attribute; throwing referencing a non-existent name; typo/case mismatch between throwing and the actual parameter name.
Related errors
- Binding of throwing parameter '{}' could not be completed as
- 'argumentNames' property of AbstractAspectJAdvice contains a
- Only afterThrowing advice can be used to bind a thrown excep
- Throwing name '{}' is neither a valid argument name nor the
- Advice method [{}] requires {} arguments to be bound by name
AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04).
Data as JSON: /data/errors/ed9e945dcea9de3b.json.
Report an issue: GitHub.