This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes returning to a catch block Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "returning to a catch block" Watch "returning to a catch block" New topic
Author

returning to a catch block

vuthlarhi donald
Ranch Hand

Joined: Jul 31, 2006
Posts: 76
how can I return to try statement froma a catch block...catching an Exception and then termionates..

chinmay s bedarkar
Greenhorn

Joined: Sep 26, 2005
Posts: 1
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

Joined: Aug 05, 2005
Posts: 3606
    
  15
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
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3606
    
  15
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

Joined: Oct 13, 2005
Posts: 39084
    
  23
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

Joined: Apr 20, 2006
Posts: 3344

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!


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
 
GeeCON Prague 2014
 
subject: returning to a catch block