JSTL Catch Tag Example:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <head> <title>c:remove Tag Example</title> </head> <body> <c:set var="salary" scope="session" value="${100000}"/> <p>Before Remove Value: <c:out value="${salary}"/></p> <c:remove var="salary"/> <p>After Remove Value: <c:out value="${salary}"/></p> <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>
As you can see above, we are trying to display result of dividing firstNumber with secondNumber. It may be possible that secondNumber is 0. In that event, exception will be thrown at run time. <c:catch> block will handle this exception and print the exception in the next <c:if> block.