After Throwing Advice
Details as well as Examples covering After Throwing Advice.
After throwing advice is executed after the target method throws an exception. It allows to handle or log exceptions thrown by the method. Some of the use cases are described below.
Exception Logging: It can be used to log exceptions and stack traces to diagnose errors and troubleshoot issues.
Notification on Error: Sending notifications or alerts to administrators or users about unexpected errors.
Resource Cleanup: Releasing resources, such as database connections or file handles, to prevent resource leaks.
Transaction Rollback: Can be used to close open transactions or rolling back database changes in response to exceptions.
Sample Example
Scenario 1: Capturing exception details via AOP
Create Aspect class
Create controller class. Assuming. some logic in the method throws exception.
DataApi.java
Run the application, trigger the API and observe the logs
Last updated
Was this helpful?