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 {
37 class Exception : public std::exception {
39 explicit Exception(int error_code, std::string file = __FILE__,
40 int line = __LINE__ ) {
41 error_code_ = error_code;
42 message_ = file.substr(file.find_last_of("/") + 1) + ":"
43 + std::to_string(line) + GetErrorString(error_code);
44 LOGE("%s", message_.c_str());
46 virtual ~Exception() {}
47 virtual const char *what(void) const noexcept {
48 return message_.c_str();
57 std::string GetErrorString(int error_code) {
59 case ERROR_INVALID_PARAMETER:
60 return ": INVALID_PARAMETER";
61 case ERROR_OUT_OF_MEMORY:
62 return ": OUT_OF_MEMORY";
65 case ERROR_PERMISSION_DENIED:
66 return ": PERMISSION_DENIED";
67 case ERROR_INVALID_OPERATION:
68 return ": INVALID_OPERATION";
70 return ": ERROR_FROM_DB";
71 case ERROR_ALREADY_EXIST_ID:
72 return ": ALREADY_EXIST_ID";
74 return ": ERROR_FROM_DBUS";
75 case ERROR_NOT_EXIST_ID:
76 return ": NOT_EXIST_ID";
77 case ERROR_SERVICE_NOT_READY:
78 return ": SERVICE_NOT_READY";
79 case ERROR_MAX_EXCEEDED:
80 return ": MAX_EXCEEDED";
87 } // namespace notification
89 #endif // NOTIFICATION_EX_EXCEPTION_H_