Lets say we have a post mapping for example that creates and returns a person object and its request body provides a first and last name that are both primary keys for some database. If either value is null then an exception is thrown.
Assuming we have another controller set up to handle the exception and intercept it with the @controlleradvice and @exceptionhandler annotations and a method that returns a ResponseEntity How does it actually intercept the exception and why does the return type of the handler not have to match the return type of the post method that threw it. Sorry if it is a silly question, i just cant seem to grasp it. I would like to understand whats happening behind the scenes.
I understand what the annotations do and hiw we specify what exception to handle, I just dont understand the how