Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Continueing after an Exception...

 
ryan headley
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Junilu Lacar
Bartender
Posts: 7482
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about putting your try/catch inside the list processing loop?
Junilu
 
ryan headley
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ryan
But now I am curious...I wonder if that would work...I am gonna hafta play with some code...
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic