">"> ">" />
Easy Tutorial
❮ Jsp Actions Jstl Core Out Tag ❯

<c:catch> Tag

JSP Standard Tag Library

The <c:catch> tag is primarily used to handle exceptions that generate errors and store the error information.

Syntax

&lt;c:catch var="<string>">
...
</c:catch>

Attributes

The <c:catch> tag has the following attributes:

Attribute Description Required Default Value
var Variable to store the error information No None

Example Demonstration

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>c:catch Tag Example</title>
</head>
<body>

&lt;c:catch var ="catchException">
   <% int x = 5/0;%>
</c:catch>

&lt;c:if test = "${catchException != null}">
   <p>The exception is : ${catchException} <br />
   An exception occurred: ${catchException.message}</p>
</c:if>

</body>
</html>

The result of the above example:

The exception is : java.lang.ArithmeticException: / by zero 
An exception occurred: / by zero

JSP Standard Tag Library

❮ Jsp Actions Jstl Core Out Tag ❯