spring-projects/spring-framework · error · IllegalArgumentException
Throwing name '{}' is neither a valid argument name nor the
Error message
Throwing name '{}' is neither a valid argument name nor the fully-qualified name of a Java type on the classpath. Root cause: {} What it means
Thrown by setThrowingNameNoCheck (line 333-349) when the throwing value is not a Java variable name and ClassUtils.forName cannot resolve it as a Throwable type on the aspect's classloader. Non-identifier throwing values are interpreted as fully-qualified exception types used to narrow which exceptions match; failure to load means binding is impossible.
Source
Thrown at spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java:344
throw new UnsupportedOperationException("Only afterThrowing advice can be used to bind a thrown exception");
}
/**
* We need to hold the throwing name at this level for argument binding calculations,
* this method allows the afterThrowing advice subclass to set the name.
*/
protected void setThrowingNameNoCheck(String name) {
// name could be a variable or a type...
if (isVariableName(name)) {
this.throwingName = name;
}
else {
// assume a type
try {
this.discoveredThrowingType = ClassUtils.forName(name, getAspectClassLoader());
}
catch (Throwable ex) {
throw new IllegalArgumentException("Throwing name '" + name +
"' is neither a valid argument name nor the fully-qualified " +
"name of a Java type on the classpath. Root cause: " + ex);
}
}
}
protected Class<?> getDiscoveredThrowingType() {
return this.discoveredThrowingType;
}
@Contract("null -> false")
private static boolean isVariableName(@Nullable String name) {
return AspectJProxyUtils.isVariableName(name);
}
/**
* Do as much work as we can as part of the set-up so that argument bindingView on GitHub (pinned to e8729d0438)
Solutions
- If throwing should bind a parameter, use the exact advice parameter name (a valid Java identifier).
- If throwing is meant to narrow by type, supply the fully-qualified Throwable subtype name and confirm it is on the classpath.
- Fix typos/package names and add the missing dependency jar.
- Remove the throwing attribute if no exception binding/narrowing is intended.
Example fix
// before <aop:after-throwing method="onEx" throwing="java.lang.RunntimeException" pointcut="..."/> // after <aop:after-throwing method="onEx" throwing="java.lang.RuntimeException" pointcut="..."/>
Defensive patterns
Strategy: validation
Validate before calling
// Validate a throwing value before setting it: identifier or loadable Throwable type.
String name = throwingValue.strip();
boolean ok = AspectJProxyUtils.isVariableName(name);
if (!ok) {
try {
Class<?> c = ClassUtils.forName(name, aspectClassLoader);
ok = Throwable.class.isAssignableFrom(c);
} catch (Throwable t) { ok = false; }
}
if (!ok) throw new IllegalArgumentException("Invalid throwing value: " + name); Try / catch
try {
((AspectJAfterThrowingAdvice) advice).setThrowingName(name);
} catch (IllegalArgumentException ex) {
throw new IllegalArgumentException(
"'throwing' must be a parameter name or fully-qualified Throwable type on the classpath: " + name, ex);
} Prevention
- Use the exact advice parameter name as the throwing value when binding.
- When narrowing by type, use a fully-qualified Throwable subtype and confirm the jar is present.
- Re-check aspect config after refactoring exception class locations.
When it happens
Trigger: Setting 'throwing' to a string that is neither a valid Java identifier nor a fully-qualified Throwable subtype resolvable by the aspect ClassLoader (typo, wrong package, missing dependency, non-Throwable type).
Common situations: Typo in the throwing attribute; using a simple class name instead of fully-qualified; the exception type lives in a jar not present at runtime; refactoring that moved the exception class without updating the aspect config.
Related errors
- Returning name '{}' is neither a valid argument name nor the
- Throwing argument name '{}' was not bound in advice argument
- 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
AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04).
Data as JSON: /data/errors/f59a4db5f7231f69.json.
Report an issue: GitHub.