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


 
 

Share on Google+Share on Google+

Multiple 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.

Multiple 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. 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>Multiple try/catch in Jsp</TITLE>
    </HEAD>
    <BODY>
    		<FONT SIZE="6" COLOR="#CC3300">Multiple try/catch in Jsp</FONT><br>
    <%
    try {
        int a[] =new int[6];
        		for(int i = 0; i<7; i++){
				 a[i]=i;
		}
    } catch (ArrayIndexOutOfBoundsException e) {
        out.println("Array index out of bounds.");
    } catch(ArithmeticException e) {
        out.println("Arithmetic exception: " + e);
    } catch(Exception e) {
        out.println("An error occurred: " + e);
    }
    %>
    </BODY>
</HTML>

Output of the Program:

Download this example.

Advertisements

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

Ask Questions?    Discuss: Multiple try catch  

Post your Comment


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