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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Example to create exception object in java 
 

Here we are describing the use of using exception class in java .This tutorial describes the way to create exception object and also to use this object appropriately in your programs and designs.

 

Example to create exception object in java

                         

The Exception object occurred when a programmer tries to access an value of an object that is out of range of the declared list.

Understand with Example 

The given below code illustrates you to illustrate an example from Exception object in java Exception. Object in java are the object of the class Exception. The program defined below describes the way to create exception object. In this program we have declare an integer array of size 2.The exception in this program occurs because we are trying to access the 7th index of the array which the array doesn't holds. The exception here displays by creating object of class exception. The exception object created here is in the following line catch (Exception ex).

ex.printStackTrace(); This is the method of the class Throw able which Prints this throw able error to the standard error stream.

Exceptionobject.java


public class Exceptionobject {

    public static void main(String[] args) {
        try {
            int arr[];
            arr = new int[2];
            arr[0] = 23;
            arr[1] = 23;
            System.out.println("Element of array at this index is " + arr[7]);
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

Output of the program

java.lang.ArrayIndexOutOfBoundsException: 7
at Exceptionobject.main(Exceptionobject.java:10)

Download source code

 

                         

» View all related tutorials
Related Tags: c exception io stack type exec uri lock this block exe row handle program to execution ram each pos ast

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 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
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

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

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

Copyright © 2008. All rights reserved.