<c:catch [var="varname"] > 需要捕获异常的代码 </c:catch>其中,varname 用来存储捕获的异常信息。
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!DOCTYPE html> <html> <head> <title>编程帮(www.lmcjl.com)</title> </head> <body> <body> <%! int num1 = 10; int num2 = 0; %> <c:catch var="errormsg"> <% int res = num1 / num2; out.println(res); %> </c:catch> <c:if test="${errormsg != null}"> <p>发生了异常,异常信息为:${errormsg}</p> </c:if> </body> </html>
发生了异常,异常信息为:java.lang.ArithmeticException:/ by zero
本文链接:http://task.lmcjl.com/news/13270.html