Reduce exception guard
[netconf.git] / netconf / netconf-netty-util / src / main / java / org / opendaylight / netconf / nettyutil / NetconfSessionPromise.java
index 178be8bfe1f3ef13ec748eb6c2c39aad2af929f7..4a8fb7f88c897b885eff082010e7b55898a165a6 100644 (file)
@@ -54,18 +54,21 @@ final class NetconfSessionPromise<S extends NetconfSession> extends DefaultPromi
 
         LOG.debug("Promise {} attempting connect for {}ms", this, timeout);
 
+        final ChannelFuture connectFuture;
         try {
             if (address.isUnresolved()) {
                 address = new InetSocketAddress(address.getHostName(), address.getPort());
             }
-            final ChannelFuture connectFuture = bootstrap.connect(address);
-            pending = connectFuture;
-            // Add listener that attempts reconnect by invoking this method again.
-            connectFuture.addListener((ChannelFutureListener) this::channelConnectComplete);
+            connectFuture = bootstrap.connect(address);
         } catch (final Exception e) {
             LOG.info("Failed to connect to {}", address, e);
             setFailure(e);
+            return;
         }
+
+        pending = connectFuture;
+        // Add listener that attempts reconnect by invoking this method again.
+        connectFuture.addListener((ChannelFutureListener) this::channelConnectComplete);
     }
 
     @Override