--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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 <exception>
+#include <string>
+
+#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_