Add SharedQueue library for appfw modules
[platform/core/base/bundle.git] / src / exception-internal.h
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef EXCEPTION_INTERNAL_H_
18 #define EXCEPTION_INTERNAL_H_
19
20 #include <string>
21 #include <exception>
22
23 #include "log-private.h"
24
25 #define THROW(error_code) throw Exception(error_code)
26
27 namespace tizen_base {
28 namespace internal {
29
30 class Exception : public std::exception {
31  public:
32   explicit Exception(int error_code, std::string file = __FILE__,
33       int line = __LINE__ ) {
34     error_code_ = error_code;
35     message_ = file.substr(file.find_last_of("/") + 1) + ":"
36         + std::to_string(line) + " code:" + std::to_string(error_code_);
37   }
38
39   virtual ~Exception() {}
40
41   virtual const char *what(void) const noexcept {
42     return message_.c_str();
43   }
44
45   int GetErrorCode() const {
46     return error_code_;
47   }
48
49  private:
50   int error_code_;
51   std::string message_;
52 };
53
54 }  // namespace internal
55 }  // namespace tizen_base
56
57 #endif  // EXCEPTION_INTERNAL_H_