It's not a secret anymore!
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

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

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

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


and you will no longer get the exception

Joanne Neal

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

Joined: Oct 13, 2005
Posts: 46349
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: 3381

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]
I agree. Here's the link:
subject: returning to a catch block
jQuery in Action, 3rd edition