When using java.net.Socket.connect()
, both a refused connection and a timeout result in a ConnectException
.
java.net.ConnectException: Connection timed out: connect
java.net.ConnectException: Connection refused: connect
How can I safely distinguish between the two? Sure parsing the error message does the job. But when the message changes in a future Java release, I'm out of luck.
The bigger picture: I'm writing a web service client using JAX-WS with a Metro implementation. When a web service call fails, I want to report the reason for the failure clearly so the issue can be resolved quickly.