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"%>
<title>Catching a risky code</title>
Division by 0 will definately cause an exception<br>
<% int x = 5/0;%>
If we come across this c:action tag that means we have overcome the exception.
The output of the program is given below:
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.