Bird
0
0

Identify the error in this advice method for logging exceptions:

medium📝 Troubleshoot Q6 of 15
Spring Boot - Aspect-Oriented Programming
Identify the error in this advice method for logging exceptions:
@AfterThrowing(pointcut = "execution(* com.example.*.*(..))", throwing = "ex")
public void logException(Exception e) {
    System.out.println("Exception: " + e.getMessage());
}
AMissing @Before annotation
BPointcut expression is invalid
CAdvice method must return a value
DParameter name mismatch between 'ex' and 'e'
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter name binding

    The throwing attribute is set to "ex" but the method parameter is named e. They must match.
  2. Step 2: Confirm other parts are correct

    The pointcut is valid, advice methods do not return values, and @Before is unrelated here.
  3. Final Answer:

    Parameter name mismatch between 'ex' and 'e' -> Option D
  4. Quick Check:

    throwing attribute name = method parameter name [OK]
Quick Trick: Match throwing attribute and parameter names exactly [OK]
Common Mistakes:
  • Using different names for throwing and parameter
  • Thinking advice must return a value
  • Confusing pointcut syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes