GeSHi (java):
/*--------------------------------------------------------------------------
//Author List:
//deAppel <Creator> www.engineeringserver.com
//
//Version: V1.0 initial release 24/OCT/2007
//Description:
// An example that creates the "java.lang.StringIndexOutOfBoundsException" on purpose
//Environment:
// This software was developed using Eclipse 3.2.2 and Java 1.6
//Copyright Information:
//Copyright (C) 2007 <Institution><None>
// Do NOT change the code or post it somewhere else
// EXCEPT www.engineeringserver.com without the author(s) (deAppel) permission!
//----------------------------------------------------------------------*/
public class StringExceptionDemo {
public static void main
(String[] args
) { String tmp =
"This is a String";
System.
out.
println("Length of the string: " + tmp.
length());
System.
out.
println(tmp.
substring(5,
9));
//Good :: prints out "is a" System.
out.
println(tmp.
substring(8,
17));
//Bad :: gives: java.lang.StringIndexOutOfBoundsException }
}
Created by GeSHI 1.0.7.20
output:Length of the string: 16
is a
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 17
at java.lang.String.substring(Unknown Source)
at StringExceptionDemo.main(StringExceptionDemo.java:10)