Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / easy-setup / mediator / richsdk / inc / ESException.h
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21
22 #ifndef EASY_SETUP_EXCEPTION_H
23 #define EASY_SETUP_EXCEPTION_H
24
25 #include <string>
26 #include <octypes.h>
27 /**
28  * @file
29  *
30  * This file contains the declaration of exception classes for easy setup
31  */
32 namespace OIC
33 {
34     namespace Service
35     {
36
37         /**
38          * The base exception class for resource encapsulation.
39          *
40          */
41         class ESException: public std::exception
42         {
43         public:
44
45             /**
46              * Constructs an exception with an empty description.
47              */
48             ESException();
49
50             /**
51              * Constructs an exception with a description.
52              *
53              * @param what The description for the error.
54              */
55             explicit ESException(const std::string &what);
56
57             /**
58              * @overload
59              */
60             explicit ESException(std::string &&what);
61
62             virtual ~ESException() noexcept;
63
64             /**
65              * Returns the exception description.
66              *
67              */
68             virtual const char *what() const noexcept;
69
70         private:
71             /**
72              *  Exception description
73              */
74             const std::string m_what;
75         };
76
77         /**
78          * Thrown when OC layer returns an error.
79          *
80          */
81         class ESPlatformException: public ESException
82         {
83         public:
84
85             /**
86              * Constructs an exception with a description.
87              *
88              * @param OCStackResult The description for the error.
89              */
90             explicit ESPlatformException(OCStackResult reason);
91
92             /**
93              * Returns the reason.
94              *
95              */
96             OCStackResult getReasonCode() const;
97
98             /**
99              * This function returns description of the exception.
100              *
101              */
102             std::string getReason() const;
103
104         private:
105             OCStackResult m_reason;
106         };
107
108         /**
109          * Thrown when a request is not acceptable.
110          *
111          */
112         class ESBadRequestException: public ESException
113         {
114         public:
115             /**
116              * Constructs an exception with a description.
117              *
118              * @param OCStackResult The description for the error.
119              */
120             explicit ESBadRequestException(const std::string& what);
121             /**
122              * @overload
123              */
124             explicit ESBadRequestException(std::string&& what);
125         };
126
127         /**
128          * Thrown when a parameter is not valid.
129          *
130          */
131         class ESInvalidParameterException: public ESException
132         {
133         public:
134             /**
135              * Constructs an exception with a description.
136              *
137              * @param OCStackResult The description for the error.
138              */
139             explicit ESInvalidParameterException(const std::string& what);
140          /**
141              * @overload
142              */
143             explicit ESInvalidParameterException(std::string&& what);
144         };
145
146         /**
147          * Thrown when getting value with wrong template parameter.
148          */
149         class ESBadGetException: public ESException
150         {
151         public:
152             /**
153              * Constructs an exception with a description.
154              *
155              * @param OCStackResult The description for the error.
156              */
157             explicit ESBadGetException(const std::string& what);
158            /**
159              * @overload
160              */
161             explicit ESBadGetException(std::string&& what);
162         };
163
164         /**
165          * Thrown when a key is invalid.
166          *
167          */
168         class ESInvalidKeyException: public ESException
169         {
170         public:
171             /**
172              * Constructs an exception with a description.
173              *
174              * @param OCStackResult The description for the error.
175              */
176             explicit ESInvalidKeyException(const std::string& what);
177              /**
178              * @overload
179              */
180             explicit ESInvalidKeyException(std::string&& what);
181         };
182     }
183 }
184
185 #endif // EASY_SETUP_EXCEPTION_H