JSTL - Core <c:catch> Tag


Advertisements

The <c:catch> tag catches any Throwable that occurs in its body and optionally exposes it. It is used for error handling and to deal more gracefully with the problem.

Attribute

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

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

Example

<%@ 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 />
         There is an exception: ${catchException.message}</p>
      </c:if>
   </body>
</html>

The above code will generate the following result −

The exception is : java.lang.ArithmaticException: / by zero
There is an exception: / by zero
jsp_standard_tag_library.htm

Useful Video Courses


Video

JSP, Servlet, JSLT + Hibernate: A complete guide

108 Lectures 11 hours

Chaand Sheikh

Video

Full Stack Java developer - Java + JSP + Restful WS + Spring

Best Seller

517 Lectures 57 hours

Chaand Sheikh

Video

Servlets and JSP Tutorial For Beginners!

41 Lectures 4.5 hours

Karthikeya T

Video

JSP and Servlets - The Complete Course

42 Lectures 5.5 hours

TELCOMA Global

Video

JSP and Servlets Bootcamp: Web Applications for Beginners

15 Lectures 3 hours

TELCOMA Global

Video

JSP (Java Server Pages) Certification Training

44 Lectures 15 hours

Uplatz

Advertisements