Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By JosAH

Thread: How to create exception object in java?

  1. #1
    Java Example is offline Moderator
    Join Date
    Sep 2014
    Rep Power

    Default How to create exception object in java?

    In this tutorial , we will discuss how to create exception object.When we try to access a value of an object which is out of range , we get ExceptionObject error.In the example below,we have declare an integer array of size 2.When we try to access the 7th index of the array which the array does not hold,exception occurs in the program.Here ,we have displayed the exception by creating the object of class exception.The ex.printStackTrace() method of the class Throwable is used which Prints this throwable error to the standard error stream.

    Java Code: To create Exception object
    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) {
    Output of the program
    java.lang.ArrayIndexOutOfBoundsException: 7
    at Exceptionobject.main(

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: How to create exception object in java?

    You don't get an ExceptionObject error; you get an ArrayOutOfBoundsException; and puhlease, keep your (incorrect) trivialities to yourself; for some reason the owner of this forum made you a Super Moderator but your silly examples that are posted here by the truck load don't help at all. It would be very much appreciated if you'd stop it.

    DarrylBurke likes this.
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. trying to create an object
    By mbw290 in forum New To Java
    Replies: 5
    Last Post: 12-07-2012, 04:02 PM
  2. What is best object to create?
    By lam5442 in forum New To Java
    Replies: 1
    Last Post: 02-23-2011, 10:44 PM
  3. Replies: 2
    Last Post: 06-22-2010, 05:29 AM
  4. create object
    By paul21 in forum New To Java
    Replies: 4
    Last Post: 03-07-2010, 08:14 PM
  5. How to create your own Exception class
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 08:40 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts