catch the execption during buildSensors

If there any sensor is being created or deleted,
the buildSenosrs will throw exceptions and the application will crash.
Add a retry logic to catch such exception and try again,
will quit the process finally if failed more than 5 times.

Tested:
Changing the PSU sensor threshold using ipmi commands,
no pid service crash log.

Signed-off-by: Yong Li <yong.b.li@linux.intel.com>
Change-Id: Icf96bfb01bce4a3b5c22095f0bef0d793fd8430d
diff --git a/main.cpp b/main.cpp
index be0691d..2ab3fc4 100644
--- a/main.cpp
+++ b/main.cpp
@@ -123,6 +123,32 @@
     }
 }
 
+void tryRestartControlLoops()
+{
+    int count = 0;
+    for (count = 0; count <= 5; count++)
+    {
+        try
+        {
+            restartControlLoops();
+            break;
+        }
+        catch (const std::exception& e)
+        {
+            std::cerr << count
+                      << " Failed during restartControlLoops, try again: "
+                      << e.what() << "\n";
+            if (count >= 5)
+            {
+                throw std::runtime_error(e.what());
+            }
+        }
+        std::this_thread::sleep_for(std::chrono::seconds(10));
+    }
+
+    return;
+}
+
 int main(int argc, char* argv[])
 {
     loggingPath = "";
@@ -155,7 +181,7 @@
      * it.
      */
 
-    restartControlLoops();
+    tryRestartControlLoops();
 
     io.run();
     return 0;