Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes Continueing after an Exception... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Continueing after an Exception..." Watch "Continueing after an Exception..." New topic

Continueing after an Exception...

ryan headley
Ranch Hand

Joined: Jun 28, 2000
Posts: 156
I thought that there was a way to continue after a caught exception has been thrown.
I.E. I have a program that reads thru a list of machine names, then goes out and sends some UDP packtes to it. If the machine is turned off, or has been renamed, I will get an UnknownHostException.
What I want to know is, once I hit a bad machine, is there a way to go on thru the rest of the list rather than die right there.
Ryan Headley

Ryan Headley<br /><a href="" target="_blank" rel="nofollow"></a>
Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

How about putting your try/catch inside the list processing loop?

Junilu - [How to Ask Questions] [How to Answer Questions]
ryan headley
Ranch Hand

Joined: Jun 28, 2000
Posts: 156
I thought about that, but the minute it hits the Exception, the program dies. Or at least it seems to.
However, the issue is a dead one now cause the problem was elsewhere...the name in the list was spelled wrong...heheh
But now I am curious...I wonder if that would work...I am gonna hafta play with some code...
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

If you properly placed your try/catch block fully within the body of your loop, and it still seemed to die... perhaps you weren't catching the right exception? Sometimes it can throw more than one. If you catch (Exception e) < which is not recommended in 'real world' > Then you will know.
ryan headley
Ranch Hand

Joined: Jun 28, 2000
Posts: 156
Coming to think of it, I am sure that was the problem. I'll just move the for loop...
Thanx guys...
Like I said earlier, it was a different issue that fixed it, but its probably good practice/syntax to move that loop!
Thanx again
I agree. Here's the link:
subject: Continueing after an Exception...
It's not a secret anymore!