Move tryCatch() implementation to separate source file.
Change-Id: Ia4614a032a022765c386144e76c58c2eec6ab6b6
${COMMON_PATH}/containers/BinaryQueue.cpp
${COMMON_PATH}/error/api.cpp
${COMMON_PATH}/error/SafeStrError.cpp
+ ${COMMON_PATH}/exceptions/TryCatch.cpp
${COMMON_PATH}/lock/FileLock.cpp
${COMMON_PATH}/log/AuditLog.cpp
${COMMON_PATH}/log/log.cpp
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+/**
+ * @file src/common/exceptions/TryCatch.cpp
+ * @author Marcin Niesluchowski <m.niesluchow@samsung.com>
+ * @author Oskar Świtalski <o.switalski@samsung.com>
+ * @version 1.0
+ * @brief This file contains an implementation of a function for catching exceptions
+ */
+
+#include <cxxabi.h>
+#include <exception>
+#include <new>
+
+#include <exceptions/AccessDeniedException.h>
+#include <exceptions/InvalidProtocolException.h>
+#include <exceptions/NoMemoryException.h>
+#include <log/log.h>
+
+#include <cynara-error.h>
+#include "TryCatch.h"
+
+namespace Cynara {
+
+int tryCatch(const std::function<int(void)> &func) {
+ try {
+ return func();
+ } catch (const std::bad_alloc &e) {
+ LOGE_NOTHROW("%s", e.what());
+ return CYNARA_API_OUT_OF_MEMORY;
+ } catch (const NoMemoryException &e) {
+ LOGE_NOTHROW("%s", e.what());
+ return CYNARA_API_OUT_OF_MEMORY;
+ } catch (const InvalidProtocolException &e) {
+ LOGE_NOTHROW("%s", e.what());
+ return CYNARA_API_INVALID_PARAM;
+ } catch (const AccessDeniedException &e) {
+ LOGE_NOTHROW("%s", e.what());
+ return CYNARA_API_PERMISSION_DENIED;
+ } catch (const std::exception &e) {
+ LOGE_NOTHROW("%s", e.what());
+ return CYNARA_API_UNKNOWN_ERROR;
+ } catch (const abi::__forced_unwind &) {
+ /**
+ * workaround for pthread_cancel, which cancels thread using this exception
+ * and expects it to be rethrown in every try-catch
+ */
+ LOGD_NOTHROW("We are 'gracefully' stopped by pthread_cancel");
+ throw;
+ } catch (...) {
+ LOGE_NOTHROW("Unexpected exception");
+ return CYNARA_API_UNKNOWN_ERROR;
+ }
+}
+
+} // namespace Cynara
+
/*
- * Copyright (c) 2014-2017 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2020 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* @author Marcin Niesluchowski <m.niesluchow@samsung.com>
* @author Oskar Świtalski <o.switalski@samsung.com>
* @version 1.0
- * @brief This file contains functions for catching exceptions
+ * @brief This file contains a declaration of a function for catching exceptions
*/
#ifndef SRC_COMMON_EXCEPTIONS_TRYCATCH_H_
#define SRC_COMMON_EXCEPTIONS_TRYCATCH_H_
-#include <cxxabi.h>
-#include <exception>
#include <functional>
-#include <new>
-
-#include <exceptions/AccessDeniedException.h>
-#include <exceptions/InvalidProtocolException.h>
-#include <exceptions/NoMemoryException.h>
-#include <log/log.h>
-
-#include <cynara-error.h>
namespace Cynara {
-int tryCatch(const std::function<int(void)> &func) {
- try {
- return func();
- } catch (const std::bad_alloc &e) {
- LOGE_NOTHROW("%s", e.what());
- return CYNARA_API_OUT_OF_MEMORY;
- } catch (const NoMemoryException &e) {
- LOGE_NOTHROW("%s", e.what());
- return CYNARA_API_OUT_OF_MEMORY;
- } catch (const InvalidProtocolException &e) {
- LOGE_NOTHROW("%s", e.what());
- return CYNARA_API_INVALID_PARAM;
- } catch (const AccessDeniedException &e) {
- LOGE_NOTHROW("%s", e.what());
- return CYNARA_API_PERMISSION_DENIED;
- } catch (const std::exception &e) {
- LOGE_NOTHROW("%s", e.what());
- return CYNARA_API_UNKNOWN_ERROR;
- } catch (const abi::__forced_unwind &) {
- /**
- * workaround for pthread_cancel, which cancels thread using this exception
- * and expects it to be rethrown in every try-catch
- */
- LOGD_NOTHROW("We are 'gracefully' stopped by pthread_cancel");
- throw;
- } catch (...) {
- LOGE_NOTHROW("Unexpected exception");
- return CYNARA_API_UNKNOWN_ERROR;
- }
-}
+int tryCatch(const std::function<int(void)> &func);
} // namespace Cynara
SET(LIB_CREDS_COMMONS_PATH ${CYNARA_PATH}/helpers/creds-commons)
SET(LIB_CREDS_COMMONS_SOURCES
+ ${CYNARA_PATH}/common/exceptions/TryCatch.cpp
${LIB_CREDS_COMMONS_PATH}/creds-commons.cpp
${LIB_CREDS_COMMONS_PATH}/CredsCommonsInner.cpp
)
#include <cynara-error.h>
#include <exceptions/TryCatch.h>
+#include <log/log.h>
#include <error/SafeStrError.h>
#include <attributes/attributes.h>
#include <exceptions/TryCatch.h>
+#include <cynara-error.h>
#include <cynara-session.h>
CYNARA_API
${CYNARA_SRC}/common/config/PathConfig.cpp
${CYNARA_SRC}/common/containers/BinaryQueue.cpp
${CYNARA_SRC}/common/error/SafeStrError.cpp
+ ${CYNARA_SRC}/common/exceptions/TryCatch.cpp
${CYNARA_SRC}/common/protocol/ProtocolAdmin.cpp
${CYNARA_SRC}/common/protocol/ProtocolFrame.cpp
${CYNARA_SRC}/common/protocol/ProtocolFrameHeader.cpp