From: Hwankyu Jhun Date: Wed, 28 Jul 2021 21:49:14 +0000 (+0900) Subject: Add missing files X-Git-Tag: submit/tizen/20210728.220216~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e4bc9f9f7f4a3d3c3606ca9550b24415ce5d3103;p=platform%2Fcore%2Fapi%2Fpreference.git Add missing files Change-Id: I78f0e2e10bc6837a07a6a69820cbbe9f11010bf2 Signed-off-by: Hwankyu Jhun --- diff --git a/preference/exception-internal.cc b/preference/exception-internal.cc new file mode 100644 index 0000000..f723ecd --- /dev/null +++ b/preference/exception-internal.cc @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#include "preference/exception-internal.hh" + +namespace preference { +namespace internal { + +Exception::Exception(int error_code, const std::string& file, int line) + : error_code_(error_code), + message_(std::move(GetErrorMessage(error_code_, file, line))) { +} + +Exception::~Exception() = default; + +const char* Exception::what() const noexcept { + return message_.c_str(); +} + +int Exception::GetErrorCode() const { + return error_code_; +} + +std::string Exception::GetErrorMessage(int error_code, const std::string& file, + int line) { + return file.substr(file.find_last_of("/") + 1) + ":" + std::to_string(line) + + " error_code: " + std::to_string(error_code); +} + +} // namespace internal +} // namespace preference diff --git a/preference/exception-internal.hh b/preference/exception-internal.hh new file mode 100644 index 0000000..da8bcbf --- /dev/null +++ b/preference/exception-internal.hh @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#ifndef PREFERENCE_EXCEPTION_INTERNAL_HH_ +#define PREFERENCE_EXCEPTION_INTERNAL_HH_ + +#include +#include + +#define THROW(error_code) throw Exception(error_code, __FUNCTION__, __LINE__) + +namespace preference { +namespace internal { + +class Exception : public std::exception { + public: + explicit Exception(int error_code, const std::string& file, int line); + virtual ~Exception(); + + virtual const char* what() const noexcept; + int GetErrorCode() const; + + private: + static std::string GetErrorMessage(int error_code, const std::string& file, + int line); + + private: + int error_code_; + std::string message_; +}; + +} // namespace internal +} // namespace preference + +#endif // PREFERENCE_EXCEPTION_INTERNAL_HH_