From 8b776fc5549f97cee12aefd41a085f4e678129ea Mon Sep 17 00:00:00 2001 From: KIM JungYong Date: Mon, 31 Oct 2016 11:34:02 +0900 Subject: [PATCH] Fix bugs for no catch std::out_of_range exceptions. 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 Reviewed-on: https://gerrit.iotivity.org/gerrit/13859 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- .../examples/linux/NestedAttributesClient.cpp | 6 +++++- .../examples/linux/SeparateResponseServer.cpp | 10 +++++++++- .../sampleapp/linux/configuration/con-client.cpp | 15 +++++++++++---- .../sampleapp/linux/configuration/con-server.cpp | 19 +++++++++++++------ 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/service/resource-encapsulation/examples/linux/NestedAttributesClient.cpp b/service/resource-encapsulation/examples/linux/NestedAttributesClient.cpp index 8188e01..4a7d87d 100644 --- a/service/resource-encapsulation/examples/linux/NestedAttributesClient.cpp +++ b/service/resource-encapsulation/examples/linux/NestedAttributesClient.cpp @@ -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 lck(mtx); cond.wait_for(lck, std::chrono::seconds(2)); diff --git a/service/resource-encapsulation/examples/linux/SeparateResponseServer.cpp b/service/resource-encapsulation/examples/linux/SeparateResponseServer.cpp index f01d1e8..4c9b4f6 100755 --- a/service/resource-encapsulation/examples/linux/SeparateResponseServer.cpp +++ b/service/resource-encapsulation/examples/linux/SeparateResponseServer.cpp @@ -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; diff --git a/service/things-manager/sampleapp/linux/configuration/con-client.cpp b/service/things-manager/sampleapp/linux/configuration/con-client.cpp index 5ba9877..67544f2 100755 --- a/service/things-manager/sampleapp/linux/configuration/con-client.cpp +++ b/service/things-manager/sampleapp/linux/configuration/con-client.cpp @@ -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) diff --git a/service/things-manager/sampleapp/linux/configuration/con-server.cpp b/service/things-manager/sampleapp/linux/configuration/con-server.cpp index 60dc232..f9bb1f6 100755 --- a/service/things-manager/sampleapp/linux/configuration/con-server.cpp +++ b/service/things-manager/sampleapp/linux/configuration/con-server.cpp @@ -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) -- 2.7.4