wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Review the code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Review the code" Watch "Review the code" New topic
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: 18508
    
  40

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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

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: http://aspose.com/file-tools
 
subject: Review the code
 
Similar Threads
about exception
error in programe
[Easy] Shift String
how to do this? (exception) can u help me to fix?
how to convert from string("a") to char..