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.
Output of the program