How to handle Host and Port Cases, when we creat a Client API

Hello folks,
i am trying to creat Connection to Elasticsearch using Client API, and i want to handle Cases , if the Host is not existing or unknown or the Port ist wrong or not existing or empty,
how to write that in java ,
here is my Start,

try {
 client = new PreBuiltTransportClient(Settings.EMPTY)
                .addTransportAddress(new TransportAddress(InetAddress
                        .getByName("localhost"), 9300));
} catch (UnknownHostException ex) {                               
            System.out.println("faild host " + ex.getMessage());
            client.close();
        }catch(UnknownTransportNummber nr){
            System.out.println("faild port" + nr.getMessage());
}

i want to check and handle the localhost , and PortNummber, is there any tutorial or Advice how to do that??
I found "UnknownHostException" to handle the Host error , is there any Exception to handle the Port error something like "UnknownTransportNummber " or "UnknownPort" ??
thx

Not sure. But anyway don't use the TransportClient as it's removed in the coming 8.0 version.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.