Ensure polling thread will not exceptionally terminate

Change-Id: I7172666a0f5767956360b1003b0df0f4aec48f75
diff --git a/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java b/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java
index dc75d84..696617b 100644
--- a/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java
+++ b/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java
@@ -186,12 +186,26 @@
     // Checks connection to devices in the config file
     // every DEFAULT_POLL_FREQUENCY_SECONDS seconds.
     private ScheduledFuture schedulePolling() {
-        return connectionExecutor.scheduleAtFixedRate(this::checkAndUpdateDevices,
+        return connectionExecutor.scheduleAtFixedRate(exceptionSafe(this::checkAndUpdateDevices),
                                                       DEFAULT_POLL_FREQUENCY_SECONDS / 10,
                                                       DEFAULT_POLL_FREQUENCY_SECONDS,
                                                       TimeUnit.SECONDS);
     }
 
+    private Runnable exceptionSafe(Runnable runnable) {
+        return new Runnable() {
+
+            @Override
+            public void run() {
+                try {
+                    runnable.run();
+                } catch (Exception e) {
+                    log.error("Unhandled Exception", e);
+                }
+            }
+        };
+    }
+
     @Override
     public void triggerProbe(DeviceId deviceId) {
         // TODO: This will be implemented later.
@@ -323,7 +337,11 @@
                     if (deviceService.getDevice(deviceId) == null) {
                         providerService.deviceConnected(deviceId, deviceDescription);
                     }
-                    checkAndUpdateDevice(deviceId, deviceDescription);
+                    try {
+                        checkAndUpdateDevice(deviceId, deviceDescription);
+                    } catch (Exception e) {
+                        log.error("Unhandled exception checking {}", deviceId, e);
+                    }
                 });
             } catch (ConfigException e) {
                 log.error("Cannot read config error " + e);