


It would be more informative if the exception thrown implied there was a problem with the range - at least something informative in the message string of the exception. Failing that, a betterĬurrently if the method substring(start, end) is called on an instance of String, and start is greater than end, then the exception thrown by the method is a StringIndexOutOfBoundsException with an out of bounds value of (end - start).įor debugging issues this is confusing, for it semantically would imply that either of the end points is out of bounds, not that there is something wrong with the range definition. IndexOutOfBoundsException, as that's more descriptive. The substring method expects two parameters: string. This method basically gets a part of the original string and returns it as a new string. I would suggest that IllegalArgumentException should be used rather than an Let’s start with the substring( ) method. The index -3 is never used, and I can't easily think of any substring Unfortunately, the message is far from helpful:Įxception in thread "main" :Īt (String.java:1443) I would expect this to give an IndexOutOfBoundsException, which it does. Note that this is also a problem in 1.3 and probably earlier. Java HotSpot(TM) Client VM (build 1.4.0-beta2-b77, mixed mode) Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta2-b77)
