@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,这个异常直接被捕获了。