<c:catch>标记捕获发生在它的身上,并选择性地暴露任何的Throwable。只需将它用于错误处理和处理这个问题更优雅。
<c:catch>标签具有以下属性:
属性 | 描述 | 必须 | 默认 |
---|---|---|---|
var | 持有java.lang.Throwable,如果抛出在主体元素的变量的名称。 | No | None |
<%@ 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