• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Review the code

 
sharon daze
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone please explain me why this code always goes into catch even exception is not thrown.



[HENRY: Add Code Tags]
 
Henry Wong
author
Marshal
Pie
Posts: 20882
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
sharon daze
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you are right
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15205
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tags when you post source code.
 
Henry Zhi Lin
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic