aspose file tools*
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
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: 18896
    
  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: 14266
    
  21

Please use code tags when you post source code.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
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