{"id":"ed9e945dcea9de3b","repo":"spring-projects/spring-framework","slug":"throwing-argument-name-was-not-bound-in-advic","errorCode":null,"errorMessage":"Throwing argument name '{}' was not bound in advice arguments","messagePattern":"Throwing argument name '(.+?)' was not bound in advice arguments","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java","lineNumber":499,"sourceCode":"\t\t\tthis.argumentBindings.put(this.argumentNames[i], i);\n\t\t}\n\n\t\t// Check that returning and throwing were in the argument names list if\n\t\t// specified, and find the discovered argument types.\n\t\tif (this.returningName != null) {\n\t\t\tif (!this.argumentBindings.containsKey(this.returningName)) {\n\t\t\t\tthrow new IllegalStateException(\"Returning argument name '\" + this.returningName +\n\t\t\t\t\t\t\"' was not bound in advice arguments\");\n\t\t\t}\n\t\t\telse {\n\t\t\t\tInteger index = this.argumentBindings.get(this.returningName);\n\t\t\t\tthis.discoveredReturningType = this.aspectJAdviceMethod.getParameterTypes()[index];\n\t\t\t\tthis.discoveredReturningGenericType = this.aspectJAdviceMethod.getGenericParameterTypes()[index];\n\t\t\t}\n\t\t}\n\t\tif (this.throwingName != null) {\n\t\t\tif (!this.argumentBindings.containsKey(this.throwingName)) {\n\t\t\t\tthrow new IllegalStateException(\"Throwing argument name '\" + this.throwingName +\n\t\t\t\t\t\t\"' was not bound in advice arguments\");\n\t\t\t}\n\t\t\telse {\n\t\t\t\tInteger index = this.argumentBindings.get(this.throwingName);\n\t\t\t\tthis.discoveredThrowingType = this.aspectJAdviceMethod.getParameterTypes()[index];\n\t\t\t}\n\t\t}\n\n\t\t// configure the pointcut expression accordingly.\n\t\tconfigurePointcutParameters(this.argumentNames, argumentIndexOffset);\n\t}\n\n\t/**\n\t * All parameters from argumentIndexOffset onwards are candidates for\n\t * pointcut parameters - but returning and throwing vars are handled differently\n\t * and must be removed from the list if present.\n\t */\n\tprivate void configurePointcutParameters(String[] argumentNames, int argumentIndexOffset) {","sourceCodeStart":481,"sourceCodeEnd":517,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java#L481-L517","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n@AfterThrowing(value = \"...\", throwing = \"ex\")\npublic void onThrow(RuntimeException error) { ... }\n// after\n@AfterThrowing(value = \"...\", throwing = \"ex\")\npublic void onThrow(RuntimeException ex) { ... }","handlingStrategy":"validation","validationCode":"// Ensure the throwing name corresponds to an actual parameter name.\nSet<String> paramNames = Set.of(new DefaultParameterNameDiscoverer().getParameterNames(adviceMethod));\nif (throwingName != null && !paramNames.contains(throwingName)) {\n    throw new IllegalStateException(\n        \"throwing='\" + throwingName + \"' is not among advice parameters \" + paramNames);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["spring-aop","aspectj","after-throwing","argument-binding","configuration"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}