JSTL Core < c:catch > 标签
<c:catch>
标签捕获发生在标签主题中的任何异常并有选择地公开它。它仅仅是用于错误处理和更得体地处理这个问题。
属性:
<c:catch>
标签具有如下所示属性:
属性 | 描述 | 是否必需 | 默认值 |
---|---|---|---|
var | 保存 java.lang 的变量名。如果抛出的 Throwable 在 body 元素内。 | 否 | 无 |
实例:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <head> <title><c:catch> Tag Example</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