|
|
catch in JSP Core Tag Library
|
Tutorials

Jsp

|
Topic |
What is "catch" tag in JSP Core Tag Library?
|
|
Explanation |
|
The catch tag of the core tag library can be used to catch the exception thrown by JSP elements, also
the exception can be stored as page scope variables.
Syntax:
<c:catch var="var" />
JSP Elements
</c:catch>
In the above syntax the exception is stored in "var" attribute.
Example:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:catch var ="iexcept">
<% int x = 7/0;%>
</c:catch>
<c:if test = "${iexcept!=null}">
The exception is :<c:out value="${iexcept}" /><br><br>
</c:if>
Result:
The exception is :java.lang.ArithmeticException: / by zero
In the above example we have used the "<c:catch" tag to get the exception got by dividing and integer
by "0" which is displayed using the variable value of the "catch" statement "iexcept". The message displayed will be
"java.lang.ArithmeticException: / by zero".
|
|
A Note |
|
JSP(Java Server Pages) is one of the most used Server Side Programming Language in the world. Simple introduction, basic program codes with examples. Begin coding your own JSP scripts with this online tutorial. Hope you enjoy this tutorial. Do send your feedback or suggestions on this JavaServer Pages tutorial. This is a copyright content.
|
|
|
|