title: Exception Thrown by Spring Jpa Repository not getting caught in Exception Handler @Controller Advice
body: <p>Below is my ExceptionHandler Class in Spring boot</p>
  
  <pre><code>@RestControllerAdvice
  public class CustomResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
  
  
  @ExceptionHandler({InvalidRequestException.class, PropertyReferenceException.class})
  public final ResponseEntity&lt;ExceptionDetails&gt; handleInvalidRequestException(InvalidRequestException ex, WebRequest request) {
      ExceptionDetails details = new ExceptionDetails(ex.getMessage(),request.getDescription(false), new Date());
      return new ResponseEntity&lt;ExceptionDetails&gt;(details, HttpStatus.BAD_REQUEST);
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Now below is the code in my service class.</p>
  
  <pre><code>@Override
  public Page&lt;Segment&gt; listSegment(int pageNum, int size, String sortBy, String direction, String app) {
          log.info("Starting to query the segment list");
          Pageable pageable = createPageRequest(size, pageNum, sortBy, direction);
          Pageable pageable = new PageRequest(page, size, dir, sortBy);
          Page&lt;Segment&gt; resultPage = segmentRepository.findByApp(app,pageable);
          if(pageNum &gt; resultPage.getTotalPages() || resultPage.getContent().isEmpty()) {
              log.info("No segment present");
              throw new ResourceNotFoundException("No Segment Present");
          }
  
          log.info("Total segment successfully fetched is: "+resultPage.getContent().size());
          if(resultPage.hasNext())
              return new Page&lt;&gt;(resultPage.getContent(), true);
          else
              return new Page&lt;&gt;(resultPage.getContent());
      }
  </code></pre>
  
  <p>In <code>sortBy</code> if I pass an invalid Column Name then this throws <code>PropertyReferenceException</code> which is not getting caught in my ExceptionHandler as code provided above and I don't know why. </p>
  
  <p>But if I catch this exception using a try-catch block in my Service layer and throw my Custom <code>InvalidRequestException</code> then this gets caught in exception handler.</p>
  
  <p>Can please someone let me know the reason and how I can catch <code>PropertyReferenceException</code> in my ExceptionHandler</p>