• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

returning to a catch block

 
vuthlarhi donald
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can I return to try statement froma a catch block...catching an Exception and then termionates..

 
chinmay s bedarkar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you put a "continue" in your catch block, then it should bring you back to the next iteration of for loop.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An ArrayOutOfBoundsException does not indicate an invalid password - it means you are trying to read outside the bounds of your array. As I told you in your previous post, change

to

and you will no longer get the exception
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, thinking about it, an ArrayOutOfBoundsException would indicate an invalid password, because you would have checked the password against all the Person objects in your array and not found a match - it is just not the best way to do it. Of course, if this is the case, there is no need to return to your try statement, because you will have already checked all the possible passwords.

The better way to do it is using a boolean flag.
 
Campbell Ritchie
Sheriff
Posts: 48378
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne is quite right; you are setting up the "for" loop wrongly, and the format for "for" loops is a standard part of beginners' Java. In my opinion catching an ArrayIndexOutOfBoundsException means minus 1 mark automatically!

Welcome to the Ranch, Chinmay S Bedarkar. The "continue" is redundant; the loop will repeat after the catch regardless.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vuthlarhi donald:
how can I return to try statement froma a catch block...


To my knowledge, it is NOT possible at all.

As all other ranchers suggested, you can alter your program code so as to resolve the issue!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic