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.

Related Topics:

JSTL c:out Core Tag with example.
JSTL c:set Core Tag with example.
JSTL c:remove Core Tag with example.
JSTL c:catch Core Tag with example.
JSTL c:if Core Tag with example.
JSTL c:choose , c:when and c:otherwise Core Tags with example.
JSTL c:import Core Tag with example.
JSTL c:forEach Core Tag with example.
JSTL c:forTokens Core Tag with example.
JSTL c:url Core Tag with example.
JSTL c:param Core Tag with example.
JSTL c:redirect Core Tag with example.