Fix bugs for no catch std::out_of_range exceptions.
authorKIM JungYong <jyong2.kim@samsung.com>
Mon, 31 Oct 2016 02:34:02 +0000 (11:34 +0900)
committerUze Choi <uzchoi@samsung.com>
Mon, 31 Oct 2016 05:12:01 +0000 (05:12 +0000)
Samples of serveral services, no catch exception about out_of_range.
With this patch, all of exception was caught.

Change-Id: I18b9cf7633ac6c6ad3d5a8b9e37a5110ffd9d68f
Signed-off-by: KIM JungYong <jyong2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/13859
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/resource-encapsulation/examples/linux/NestedAttributesClient.cpp
service/resource-encapsulation/examples/linux/SeparateResponseServer.cpp
service/things-manager/sampleapp/linux/configuration/con-client.cpp
service/things-manager/sampleapp/linux/configuration/con-server.cpp

index 8188e01..4a7d87d 100644 (file)
@@ -262,10 +262,14 @@ bool discoverResource()
         RCSDiscoveryManager::getInstance()->discoverResourceByType(RCSAddress::multicast(),
                 resourceType, &onResourceDiscovered);
     }
-    catch(const RCSPlatformException& e)
+    catch (const RCSPlatformException& e)
     {
          std::cout << e.what() << std::endl;
     }
+    catch (...)
+    {
+         std::cout << "unknown exception" << std::endl;
+    }
     std::unique_lock<std::mutex> lck(mtx);
     cond.wait_for(lck, std::chrono::seconds(2));
 
index f01d1e8..4c9b4f6 100755 (executable)
@@ -151,7 +151,15 @@ void selectResourceType()
 
 int main(void)
 {
-    selectResourceType();
+    try
+    {
+        selectResourceType();
+    }
+    catch(...)
+    {
+        std::cout << "Can't select Resource Type" << std::endl;
+        return -1;
+    }
 
     std::cout << "Resource successfully created!" << std::endl;
 
index 5ba9877..67544f2 100755 (executable)
@@ -536,11 +536,18 @@ int main()
                     continue;
                 }
 
-                if (g_thingsMnt->reboot(g_maintenanceCollection, &onReboot) != OC_STACK_ERROR)
+                try
                 {
-                    pthread_mutex_lock(&mutex_lock);
-                    isWaiting = 0;
-                    pthread_mutex_unlock(&mutex_lock);
+                    if (g_thingsMnt->reboot(g_maintenanceCollection, &onReboot) != OC_STACK_ERROR)
+                    {
+                        pthread_mutex_lock(&mutex_lock);
+                        isWaiting = 0;
+                        pthread_mutex_unlock(&mutex_lock);
+                    }
+                }
+                catch(...)
+                {
+                    std::cout<<"Reboot fail." << std::endl;
                 }
             }
             else if (g_Steps == 10)
index 60dc232..f9bb1f6 100755 (executable)
@@ -291,15 +291,22 @@ int main()
             }
             else if (g_Steps == 1)
             {
-                if( g_thingsConf->doBootstrap(&onBootstrap) == OC_STACK_OK)
+                try
                 {
-                    pthread_mutex_lock(&mutex_lock);
-                    isWaiting = 1;
-                    pthread_mutex_unlock(&mutex_lock);
+                    if( g_thingsConf->doBootstrap(&onBootstrap) == OC_STACK_OK)
+                    {
+                        pthread_mutex_lock(&mutex_lock);
+                        isWaiting = 1;
+                        pthread_mutex_unlock(&mutex_lock);
+                    }
+                    else
+                    {
+                        std::cout << "A callback pointer of the function is NULL." << std::endl;
+                    }
                 }
-                else
+                catch(...)
                 {
-                    std::cout << "A callback pointer of the function is NULL." << std::endl;
+                     std::cout << "doBootstrap fail." << std::endl;
                 }
             }
             else if (g_Steps == 2)