异常没被捕获呀。。。
我按课程代码写的异常没被捕获,什么情况? package handler; import com.imooc.domain.Result; import com.imooc.utils.ResultUtil; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; /** * Created by MBENBEN on 2017/6/18. */ @ControllerAdvice public class ExceptionHandle { @ExceptionHandler(value = Exception.class) @ResponseBody public Result handle(Exception e){ return ResultUtil.error(100,e.getMessage()); } } service里 public void getAge(Integer id) throws Exception{ Girl girl= girlRepository.findOne(id); Integer age=girl.getAge(); if(age<10){ throw="" new="" else="" age="">10 && age<16){ //你可能还在上初中 throw new Exception("你可能还在上初中"); } //如果大于16岁 } controller里 @GetMapping(value = "girls/getAge/{id}") public void getAge(@PathVariable("id") Integer id) throws Exception{ girlService.getAge(id); }