@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";
   }

02. Spring Boot异常处理[email protected](二)

 02. Spring Boot异常处理[email protected](二)

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

02. Spring Boot异常处理[email protected](二)

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

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

02. Spring Boot异常处理[email protected](二)

 

 

相关文章:

  • 2022-01-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-21
  • 2021-12-09
  • 2021-07-22
  • 2021-07-06
猜你喜欢
  • 2021-07-10
  • 2021-07-25
  • 2021-10-02
  • 2021-08-22
  • 2021-08-21
相关资源
相似解决方案