Free CoreJava Programs Source codes | Examples | Video Tutorials Download

Wednesday, January 21, 2009

StringIndexOutOfBoundsException Program

package day3_4;

/**

* General stringindexoutofboundsexception .

*

* @author Ritesh

*

*/

public class StringTest {

/**

* Generates exception : StringIndexOutOfBoundsException

*

*/

public static void generateStringIndexOutOfBoundException() {

try {

// creating one temporary string

String strTemp = "RAM";

// generate error

strTemp.charAt(3);

} catch (StringIndexOutOfBoundsException e) {

System.out.println("Error : string index out of bounds exception");

e.printStackTrace();

}

}

/**

* execution begin from here

*

* @param args

* command line arguments

*/

public static void main(String[] args) {

generateStringIndexOutOfBoundException();

}

}

No comments:

Post a Comment

Followers