nerdexam
Broadcom-VMware

2V0-72.22PSE · Question #16

Which statement describes the @AfterReturning advice type? (Choose the best answer.)

The correct answer is A. The advice is invoked only if the method returns successfully but not if it throws an exception. @AfterReturning fires exclusively on a successful method return - if the method throws an exception, the advice is skipped entirely, making option A the precise definition. Why the distractors are wrong: B (truncated, but describes running "even if" something) points to @After…

Core Spring

Question

Which statement describes the @AfterReturning advice type? (Choose the best answer.)

Options

  • AThe advice is invoked only if the method returns successfully but not if it throws an exception.
  • BThe @AfterReturning advice allows behavior to be added after a method returns even if it
  • CThe advice has complete control over the method invocation; it could even prevent the method
  • DTypically used to prevent any exception, thrown by the advised method, from propagating up

How the community answered

(22 responses)
  • A
    86% (19)
  • B
    5% (1)
  • C
    9% (2)

Explanation

@AfterReturning fires exclusively on a successful method return - if the method throws an exception, the advice is skipped entirely, making option A the precise definition.

Why the distractors are wrong:

  • B (truncated, but describes running "even if" something) points to @After (a.k.a. "after finally"), which runs regardless of whether the method succeeds or throws - that's the key difference from @AfterReturning.
  • C describes @Around advice, which wraps the entire method invocation and can even prevent the target method from executing at all.
  • D describes @AfterThrowing, which is triggered specifically by exceptions propagating out of the advised method.

Memory tip: Think of @AfterReturning as a success-only callback - it only "celebrates" when the method comes home safely. If anything goes wrong (exception), the party is cancelled. Contrast this with @After (the "always runs" finally block) and @AfterThrowing (the "only runs on disaster" handler).

Topics

#AOP Advice Types#@AfterReturning#Exception Handling#Method Interception

Community Discussion

No community discussion yet for this question.

Full 2V0-72.22PSE Practice