Home Jsp Simple-jsp-example Nested try catch
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Nested try catch

Advertisement
The code which can throw exception should be written in the try block. If the exceptions occurs at that particular block then it will be catch by the catch block. We can have more than one try/catch block.

Nested try catch

        

The code which can throw exception should be written in the try block.  If the exceptions occurs at that particular block then it will be catch by the catch block. We can have more than one try/catch block. We can declare multiple try blocks inside the try block. The most specific exception which can be thrown is written on the top in the catch block following by the less specific least. 

 

The code of the program is given program:  

 

<HTML>
    <HEAD>
    <TITLE>Nesting try/catch Statements in jsp</TITLE>
   </HEAD>
  <BODY>
<FONT SIZE="5" COLOR="#666600">Nesting try/catch Statements in jsp</FONT>
   <%
        try {
	int c[] = {0, 1, 2, 3};
            try {
                c[5] = 5;
            } catch(ArrayIndexOutOfBoundsException e) {
                out.println("<br>Array index out of bounds: " + e);
            }
		int a=c[3]/c[0];
          } catch(ArithmeticException e) {
            out.println("<br>Divide by zero: " + e);
        }
        %>
    </BODY>
</HTML>

Output of the Program:

Download this example

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 12, 2008

Related Tutorials

Ask Questions?    Discuss: Nested try catch  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com