Improve handling of uncaught exceptions in client library 39/93239/2
authorRafal Krypa <r.krypa@samsung.com>
Fri, 21 Oct 2016 07:45:54 +0000 (09:45 +0200)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Fri, 21 Oct 2016 08:43:13 +0000 (01:43 -0700)
For easier debugging of unexpected client behaviour where an unexpected
exception is caught in try_cacth wrapper, make the following enhancements:
- Catch all SecurityManager::Exceptions instead of letting them to be
  caught by last resort "catch(...)". This will enable proper error messages.
- Print the information about unexpected exception to stderr of the caller.

Change-Id: I67edc718daa89023d5844e31f52b745257914e1f
Signed-off-by: Rafal Krypa <r.krypa@samsung.com>
src/client/client-common.cpp

index cb7e13c..bce0cc8 100644 (file)
@@ -22,6 +22,8 @@
  * @brief       This file is implementation of client-common functions.
  */
 
+#include <iostream>
+
 #include <fcntl.h>
 #include <poll.h>
 #include <sys/types.h>
@@ -54,12 +56,15 @@ int try_catch(const std::function<int()>& func)
 {
     try {
         return func();
-    } catch (MessageBuffer::Exception::Base &e) {
-        LogError("SecurityManager::MessageBuffer::Exception " << e.DumpToString());
-    } catch (std::exception &e) {
+    } catch (const Exception &e) {
+        LogError("SecurityManager::Exception " << e.DumpToString());
+        std::cerr << "SecurityManager::Exception " << e.DumpToString() << std::endl;
+    } catch (const std::exception &e) {
         LogError("STD exception " << e.what());
+        std::cerr << "STD exception " << e.what() << std::endl;
     } catch (...) {
-        LogError("Unknown exception occured");
+        LogError("Unknown exception occurred");
+        std::cerr << "Unknown exception occurred" << std::endl;
     }
     return SECURITY_MANAGER_ERROR_UNKNOWN;
 }