02. Spring Boot异常处理-@ExceptionHandler(二)

 @ExceptionHandle 注解处理异常

@Controller
public class DemoController {
   
   @RequestMapping("/show")
   public String showInfo(){
      String str = null;
      str.length();
      return "index";
   }
   
   @RequestMapping("/show2")
   public String showInfo2(){
      int a = 10/0;
      return "index";
   }

 

看页面: error1,error2.两个页面一样

 步骤:首先访问http://localhost:8080/show2

然后会出现:异常java.lang.ArithmeticException,这个异常直接被捕获了。

猜你喜欢

转载自blog.csdn.net/qq_40979622/article/details/83188452