From 808c31d37791c40453a4e49af7438c9337086a43 Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Fri, 21 Oct 2016 09:45:54 +0200 Subject: [PATCH] Improve handling of uncaught exceptions in client library 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 --- src/client/client-common.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/client/client-common.cpp b/src/client/client-common.cpp index cb7e13c..bce0cc8 100644 --- a/src/client/client-common.cpp +++ b/src/client/client-common.cpp @@ -22,6 +22,8 @@ * @brief This file is implementation of client-common functions. */ +#include + #include #include #include @@ -54,12 +56,15 @@ int try_catch(const std::function& 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; } -- 2.7.4