Throwing Exceptions in Spring AOP

Every time I read the official AOP Spring documentation ( link ), I am embarrassed by the behavior of the RuntimeExceptions tips. Will someone check the correctness of my explanation for the following tips?

@Before

  • Council throws Exception = Target (not executed) Council (executed)
  • Target throws Exception = Target (in progress) Tip (in progress)

@AfterReturning

  • Board throws Exception = Target (in progress) Council (in progress)
  • Target throws Exception = Target (executed) Tip (not executed)

@AfterThrowing

  • Board throws Exception = Target (in progress) Board (not in effect)
  • Target throws Exception = Target (in progress) Tip (in progress)

@After

  • Board throws Exception = Target (in progress) Council (in progress)
  • Target throws Exception = Target (in progress) Tip (in progress)

@Around

  • Board throws Exception = Target (in progress) Council (in progress)
  • Target throws Exception = Target (executed) Tip (executed before point.proceed ())
+7
source share
1 answer

This is how I usually look at it.

try { //@Before method(); //@AfterReturning } catch(Throwable t) { //@AfterThrowing } finally { //@After } 

@Around is a kind of beast. Since you choose when to call the target, you can catch any Exception , it can throw . Therefore, you can easily wrap the call in try-catch-finally and gain access to all and all the connection points mentioned earlier.

I assume that when you say "done," you mean "done to such an extent that an exception has been thrown."

Another important thing for you is the @Order annotation. Higher @Order values ​​are found first on the front side, and they work independently backward. Make sure you keep this in mind when combining several tips for the same purpose.

+12
source

All Articles