We may want to handle only ConnectionException. This should work fine for Mac and Linux. But Windows JVM does not raise ConnectionException in case of connection refused.