2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef NOTIFICATION_EX_EXCEPTION_H_
18 #define NOTIFICATION_EX_EXCEPTION_H_
25 #include "notification-ex/common.h"
31 #define LOG_TAG "NOTIFICATION_EX"
33 #define THROW(error_code) throw Exception(error_code, __FILE__, __LINE__)
35 namespace notification {
38 class Exception : public std::exception {
40 explicit Exception(int error_code, std::string file = __FILE__,
41 int line = __LINE__ ) {
42 error_code_ = error_code;
43 message_ = file.substr(file.find_last_of("/") + 1) + ":"
44 + std::to_string(line) + GetErrorString(error_code);
45 LOGE("%s", message_.c_str());
47 virtual ~Exception() {}
48 virtual const char *what(void) const noexcept {
49 return message_.c_str();
58 std::string GetErrorString(int error_code) {
60 case ERROR_INVALID_PARAMETER:
61 return ": INVALID_PARAMETER";
62 case ERROR_OUT_OF_MEMORY:
63 return ": OUT_OF_MEMORY";
66 case ERROR_PERMISSION_DENIED:
67 return ": PERMISSION_DENIED";
69 return ": ERROR_FROM_DB";
70 case ERROR_ALREADY_EXIST_ID:
71 return ": ALREADY_EXIST_ID";
73 return ": ERROR_FROM_DBUS";
74 case ERROR_NOT_EXIST_ID:
75 return ": NOT_EXIST_ID";
76 case ERROR_SERVICE_NOT_READY:
77 return ": SERVICE_NOT_READY";
85 } // namespace notification
87 #endif // NOTIFICATION_EX_EXCEPTION_H_