ws-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Taft <a...@hydroblaster.com>
Subject Re: Exception in thread doesn't return error code to system
Date Mon, 20 Feb 2006 20:46:46 GMT

In the version of the XmlRpc library I'm using (1.2-b1), the exception 
you're getting is actually being thrown by the WebServer.run() method. 
It looks like WebServer.start() is spawning a new thread to invoke 
WebServer.run().

Therefore, you'd probably be best to override WebServer.run(). 
Something like:

class MyWebServer extends WebServer {
   public void run() {
     try {
       super.run();
     } catch (Exception e) {
       System.exit(<n>);
     }
   }
}


Another possible idea would be to open up a "normal" socket on your port 
and catch any errors you get.  Then, you'd close it and start your 
server on the same port.

The specific error you're getting, as I'm sure you know, is because 
you've already got a socket open / server listening on the specified 
port.  Trying to open a listener on that port should give you the same 
error back, but in a more predictable way (since it would be on the same 
thread).

Your startup shell script could/should also be looking for running 
versions of your server and fail if it already sees a version running. 
This would be a pretty smart thing to do regardless of what exceptions 
you're trying to catch.


Markus Fischer wrote:
> Hi,
> 
> Adam Taft wrote:
>> Markus Fischer wrote:
>>> I'm not very confident with Java so I wasn't able to figure out how I
>>> can signal the shell that an error occurred in this special case.
>> Catch the error and then do:
>>
>> System.exit(n);
>>
>> where n is the error number you want to return to the shell.
> 
> I tried being that clever, but it seems that I was trying to catch the
> Exception in the wrong place. My code looks like this:
> 
> WebServer webserver = new WebServer (port);
> webserver.addHandler(handler, object);
> webserver.start ();
> 
> When the BindException is thrown he's in start() method, putting the
> exception block around it doesn't catch it.
> 
> I *think* if it would have been thrown there I would have gotten the
> right return value on the shell but it isn't.
> 
> thanks,
> - Markus
> 

Mime
View raw message