I have created a custom exception handler in Spring Boot:
@RestControllerAdvice
public class DataApiExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(NoSuchElementException.class)
public final void **handleNoSuchElementException**(NoSuchElementException ex) {
System.err.println("This is throwing :"+ex.getMessage());
}
...
@ExceptionHandler({ Exception.class })
public ResponseEntity<Object> **handleAll**(final Exception ex) {
...
and it's throwing exception like
throw new NoSuchElementException("SomelogicalDescription");
but each time I throw this NoSuchElementException, handleAll is executed instead of handleNoSuchElementException.
I might be missing something very trivial. To change NoSuchElementException with NotFoundException does not make any difference.