| Author |
Review the code
|
sharon daze
Greenhorn
Joined: Feb 08, 2009
Posts: 16
|
|
Anyone please explain me why this code always goes into catch even exception is not thrown.
[HENRY: Add Code Tags]
|
http://myjvm.wordpress.com
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16681
|
|
Anyone please explain me why this code always goes into catch even exception is not thrown
Well, if you had printed the exception in the catch block, you can see the reason for yourself.
But just by "eyeballing" (without running it), my guess would be because of an out of bounds exception.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
sharon daze
Greenhorn
Joined: Feb 08, 2009
Posts: 16
|
|
|
Yes you are right
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12907
|
|
|
Please use code tags when you post source code.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Henry Zhi Lin
Ranch Hand
Joined: Nov 04, 2008
Posts: 69
|
|
sharon daze wrote:Anyone please explain me why this code always goes into catch even exception is not thrown.
That's the bit of code causes your exception. String index start from 0 to String.length() -1, and you pass String.length will result index out of bound exception.
|
SCJP 5.0
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: Review the code
|
|
|