Can't springmvc's exception handlers catch mysql exceptions?

A self-defined exception handling class is defined by using the exception handling mechanism of springmvc. After testing:

  1. 1 RuntimeException thrown by
  2. can be captured.
  3. if you customize the exception class and throw it manually, you can also catch.
  4. but the mysql exception does not go into the exception handling class . (such as com.mysql.jdbc.exceptions.jdbc4.CommunicationsException )

exception handling class:

@ControllerAdvice
public class CustomerExceptionResolver  implements HandlerExceptionResolver {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e) {
        e.printStackTrace();
        //
        log.error(":",e);
        ....

service method:

public ResponseResult selectByName4Smart(String name) throws CustomException {
        //mapper
        //mysql, 
        //
        List<String> certNos = customerMapper.selectCertNosLikeName(name);
        ...
The exception of

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException has not been tried, and its indirect parent class, java.sql.SQLException, can be caught if I try.

Menu