JSTL c:catch Core Tag

The JSTL <c:catch> Core Tag is used in exception handling to catch any Throwable object in its body.

Syntax:

<c:catch var ="variableName">
   //exception code
</c:catch>

c:catch tag attributes:

Attribute Description Required
var It specify the name of the variable to hold the java.lang.Throwable if thrown by elements in the body. No

Example:

test.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
 
<html>
	<head>
		<title>c:catch JSTL core tag example</title>
	</head>
	<body>
		<c:catch var ="exception">
   			<% int x = 10/0;%>
		</c:catch>
 
		<c:if test = "${exception != null}">
		   Occurred exception is : ${exception}
		</c:if>
	</body>
</html>

web.xml

<web-app>
 
  <welcome-file-list>
          <welcome-file>test.jsp</welcome-file>
  </welcome-file-list>	
 
</web-app>

Output:

jsp example 34   Download this example.   Next Topic: JSTL c:if Core Tag with example. Previous Topic: JSTL c:remove Core Tag with example.

 

Please follow and like us:
Content Protection by DMCA.com