它用于捕获体内发生的任何Throwable异常, 并有选择地公开它。通常, 它用于错误处理并更轻松地处理程序中出现的问题。
<c:catch>标记捕获程序主体中发生的任何异常。
让我们看一下c:catch标签的简单示例:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>Core Tag Example</title>
</head>
<body>
<c:catch var ="catchtheException">
<% int x = 2/0;%>
</c:catch>
<c:if test = "${catchtheException != null}">
<p>The type of exception is : ${catchtheException} <br />
There is an exception: ${catchtheException.message}</p>
</c:if>
</body>
</html>
输出:
The type of exception is : java.lang.ArithmaticException: / by zero
There is an exception: / by zero
评论前必须登录!
注册