Home Jsp Simple-jsp-example Catching Exception usin c: catch



Catching Exception usin c: catch
Posted on: March 12, 2008 at 12:00 AM
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

Catching Exception usin 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 using the scriptlet inside the <c:action>. The code inside the scriptlet will definitely throw an exception. The exception will be caught inside the <c:catch> core action tag instead of sending it to the error page. 

The code of the program is given below:

 

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%@ page errorPage="JSTLErrorPage.jsp"%>
<html>
<head>
<title>Catching a risky code</title>
</head>
<body>
<c:catch>
Division by 0 will definately cause an exception<br>
<% int x = 5/0;%>
</c:catch>

If we come across this c:action tag that means we have overcome the exception. 
</body>
</html>

The output of the program is given below:

Download this example.

        

Related Tags for Catching Exception usin c: catch:
javacexceptionlibraryerroridescriptioippagevicoretaglockusingthisidactionblockwriteinvokerowlikehandleifexamplesolutionworkelfsendtoiniexamselfldshcodesboteilthrowitdeslibcanliinitulfromartceinnorarpartmntpartrsidsidethinstiosbeacaosletjadcatchesscriptletsendingrecoverendageovericulocmehrprocatdoxawhichxampuattryssusoatanykisinkhalllfmpleadoubtcoverexceptandaractbeautycodcodeconfrtwrittenvautittscrssriripteathshoavstatihatendingfinidentidentpleplprndodeonomolo


More Tutorials from this section

Ask Questions?    Discuss: Catching Exception usin c: catch  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.