0

I've a MQ Spring Boot PaaS application where I need to implement exception handling via a common exception handler class (GlobalExceptionHandler). My PaaS application receives message from a source queue, perform some database operations via spring jpa and write the response back to a destination queue.

I need to handle all the database RuntimeException, custom business exceptions and other checked exceptions via GlobalExceptionHandler class.

My GlobalExceptionHandler will have handlers (method) defined for every exception. In my handler, I will be logging the exception first and then I will be creating a [error code, desc] and then I need to return it back to main flow.

I do not have any controller in my application. So I think, I can't use @ControllerAdvice. Currently I'm using spring AOP @AfterThrowing as below but I'm not able to return the [code, desc] from handlers.

@AfterThrowing(pointcut = "execution(* com.abc.xyz.service..*(..)) ", 
throwing = "dataNotFoundException")
    public void handleDataNotFoundException(DataNotFoundException dataNotFoundException) {
       LOGGER.info("Info : " + dataNotFoundException.getMessage());
       // code, desc need to create here and send it back to calling place.
       // I need to change the return type here from void.
    }

Can anyone please guide me in implementing exception handling here.

1 Answer 1

0

As I explained here, @AfterThrowing cannot modify return values or otherwise change the execution flow of your epplication. You cannot even catch the exception there. You need to use an @Around advice instead.

I suggest you read some documentation first and then ask more follow-up questions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.