Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / service / resource-encapsulation / include / RCSException.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 defines a class to handle exception thrown for resource encapsulation.
25  */
26
27 #ifndef RES_ENCAPSULATION_RCSEXCEPTION_H
28 #define RES_ENCAPSULATION_RCSEXCEPTION_H
29
30 #include <string>
31
32 #include <octypes.h>
33
34 namespace OIC
35 {
36     namespace Service
37     {
38
39         /**
40          * The base exception class for resource encapsulation.
41          *
42          */
43         class RCSException: public std::exception
44         {
45         public:
46
47             /**
48              * Constructs an exception with an empty description.
49              */
50             RCSException();
51
52             /**
53              * Constructs an exception with a description.
54              *
55              * @param what The description for the error.
56              */
57             explicit RCSException(const std::string &what);
58
59             /**
60              * @overload
61              */
62             explicit RCSException(std::string &&what);
63
64             virtual ~RCSException() noexcept;
65
66             /**
67              * Returns the exception description.
68              *
69              */
70             virtual const char *what() const noexcept;
71
72         private:
73             /**
74              *  Exception description
75              */
76             const std::string m_what;
77         };
78
79         /**
80          * Thrown when OC layer returns an error.
81          *
82          */
83         class PlatformException: public RCSException
84         {
85         public:
86             explicit PlatformException(OCStackResult reason);
87
88             /**
89              * Returns the reason.
90              *
91              */
92             OCStackResult getReasonCode() const;
93
94             /**
95              * Returns the reason description.
96              *
97              */
98             std::string getReason() const;
99
100         private:
101             OCStackResult m_reason;
102         };
103
104         /**
105          * Thrown when a request is not acceptable.
106          *
107          */
108         class BadRequestException: public RCSException
109         {
110         public:
111             explicit BadRequestException(const std::string& what);
112             explicit BadRequestException(std::string&& what);
113         };
114
115         /**
116          * Thrown when a parameter is not valid.
117          *
118          */
119         class InvalidParameterException: public RCSException
120         {
121         public:
122             explicit InvalidParameterException(const std::string& what);
123             explicit InvalidParameterException(std::string&& what);
124         };
125
126         /**
127          * Thrown when getting value with wrong template parameter.
128          */
129         class BadGetException: public RCSException
130         {
131         public:
132             explicit BadGetException(const std::string& what);
133             explicit BadGetException(std::string&& what);
134         };
135
136         /**
137          * Thrown when a key is invalid.
138          *
139          */
140         class InvalidKeyException: public RCSException
141         {
142         public:
143             explicit InvalidKeyException(const std::string& what);
144             explicit InvalidKeyException(std::string&& what);
145         };
146
147     }
148 }
149
150 #endif // RES_ENCAPSULATION_RCSEXCEPTION_H