English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

<c:catch> tag

JSP Standard Tag Library

<c:catch> tag is mainly used to handle exceptions that occur and store error information.

Grammar format

<c:catch var="<string>">
...
</c:catch>

Attribute

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

AttributeDescriptionIs Necessary Default Value
varVariable used to store error informationNoNone

Example Demonstrates

<%@ 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>
<c:catch var ="catchException">
   <% int x = 5/0;%>
</c:catch>
<c:if test = "${catchException != null}">
   <p>The exception is: ${catchException} <br />
   An exception occurred: ${catchException.message}</p>
</c:if>
</body>
</html>

The running result of the above example is:

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

JSP Standard Tag Library