This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Properly Catching an Unknown Host exception  RSS feed

 
Tristan Havelick
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a front end for telneting directly into pop mail servers that I have a couple small, but related bugs in.
First let me explain how the program works a little bit. You can get the source code here: RawMail.java The main class, RawMail handles all the GUI, event trapping etc. The NetThread class extends Thread and handles all the socket related code.
The Problem
when someone types a non-existant server, the program throws a UnknownHostException. This exception is thrown in NetTread after the Connect button is disabled. Cuerrently I catch the exception in the NetThread code; which means I can't put the button disabling code in the same try clause. to remedy this I would just throw the exception up to the GUI code but I cant because the socket is opened in NetTread's run() method, so I can't write
public void run() throws UnkownHostExeception
how can I get around this?
Second:
for debuging purposes, I commented out the code that disables the 'connect' button. If the user types a non-existent host, it throws (and catches) an UnknownHostException. The strange part is if the user then puts in a valid host the second time the connect button does nothing! why?
Thanks in advance,
=-<Tristan>
 
Tristan Havelick
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved it myself! Basically I created a method checkHost(String host) that used InrtAddres.getByName(host). ... ok I stole it from a book, but it seems to work. I'm still not sure what was causing the second problem, but this seems to have bypassed it.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!