Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions? | Software Development
 

JSTL

If you have written some code which you think that it can invoke a error, and still you are confident that you can recover from that solution by yourself. Then then is one tag provided to you that is which is one of the tag of core action librar

JSTL <c: catch>

                          

If you have written some code which you think that it can invoke a error, and still you are confident that you can recover from that solution by yourself. Then then is one tag provided to you that is <c:catch> which is one of the tag of core action library. It works like a try/catch block in java. 

If we have any doubt that the particular code can invoke a error then we should write those codes inside the <c:catch> core action tag. The beauty of this tag is that it works both like a try and catch. There is no such thing like try tag. This tag can handle both the try and catch situation. 

In this example we are going to use the var attribute of the <c:catch> core action. This attribute is optional that means it is not mandatory. This attribute is used when we want to access the exception after the end of the <c:catch> tag.  In this example we have also used one more tag that is <c:if>, which we are using to check the condition. 

The code of the program is given below:

 

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
<head>
<title>Catching the Exception</title>
</head>
<body>
<strong>I can catch the exception:</strong><br>
<c:catch var ="catchException">
The exception will be thrown inside the catch:<br>
<% int x = 5/0;%>
</c:catch>

<c:if test = "${catchException!=null}">
The exception is : ${catchException}<br><br>
There is an exception: ${catchException.message}<br>
</c:if>

</body>
</html>

The output of the program is given below:

Download this example.

                          

» View all related tutorials
Related Tags: c math ide data div vi value number ddl id set element elements average mount to e ics in cs

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
 
Tell A Friend
Your Friend Name

 
Recently Viewed
Software Solutions
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map | Privacy Policy

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.