78723d8cfafbedf49e9cc58c034fe18e9b76dc02
[platform/upstream/iotivity.git] / service / easy-setup / sdk / mediator / include / 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  * @file
23  *
24  * This file contains the declaration of exception classes for easy setup
25  */
26 #ifndef EASY_SETUP_EXCEPTION_H
27 #define EASY_SETUP_EXCEPTION_H
28
29 #include <string>
30 #include <octypes.h>
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             explicit ESPlatformException(OCStackResult reason);
85
86             /**
87              * Returns the reason.
88              *
89              */
90             OCStackResult getReasonCode() const;
91
92             /**
93              * Returns the reason description.
94              *
95              */
96             std::string getReason() const;
97
98         private:
99             OCStackResult m_reason;
100         };
101
102         /**
103          * Thrown when a request is not acceptable.
104          *
105          */
106         class ESBadRequestException: public ESException
107         {
108         public:
109             explicit ESBadRequestException(const std::string& what);
110             explicit ESBadRequestException(std::string&& what);
111         };
112
113         /**
114          * Thrown when a parameter is not valid.
115          *
116          */
117         class ESInvalidParameterException: public ESException
118         {
119         public:
120             explicit ESInvalidParameterException(const std::string& what);
121             explicit ESInvalidParameterException(std::string&& what);
122         };
123
124         /**
125          * Thrown when getting value with wrong template parameter.
126          */
127         class ESBadGetException: public ESException
128         {
129         public:
130             explicit ESBadGetException(const std::string& what);
131             explicit ESBadGetException(std::string&& what);
132         };
133
134         /**
135          * Thrown when a key is invalid.
136          *
137          */
138         class ESInvalidKeyException: public ESException
139         {
140         public:
141             explicit ESInvalidKeyException(const std::string& what);
142             explicit ESInvalidKeyException(std::string&& what);
143         };
144     }
145 }
146
147 #endif // EASY_SETUP_EXCEPTION_H