<c:catch>

<c:catch> 标签

<c:catch> 标签主要用来处理产生错误的异常状况,并且将错误信息储存起来。


属性

<c:catch>标签有如下属性:

属性 描述 是否必要 默认值
var 用来储存错误信息的变量 None

实例演示

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>c:catch 标签实例</title>
</head>
<body>

<c:catch var ="catchException">
   <% int x = 5/0;%>
</c:catch>

<c:if test = "${catchException != null}">
   <p>The exception is : ${catchException} <br />
   There is an exception: ${catchException.message}</p>
</c:if>

</body>
</html>

以上实例运行结果:

The exception is : java.lang.ArithmaticException: / by zero
There is an exception: / by zero
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3