Add missing files 13/261913/1
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 28 Jul 2021 21:49:14 +0000 (06:49 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 28 Jul 2021 21:49:14 +0000 (06:49 +0900)
Change-Id: I78f0e2e10bc6837a07a6a69820cbbe9f11010bf2
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
preference/exception-internal.cc [new file with mode: 0644]
preference/exception-internal.hh [new file with mode: 0644]

diff --git a/preference/exception-internal.cc b/preference/exception-internal.cc
new file mode 100644 (file)
index 0000000..f723ecd
--- /dev/null
@@ -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 (file)
index 0000000..da8bcbf
--- /dev/null
@@ -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 <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_