a47b1e420f06e2f1ed8c6207323896fc6ba538ce
[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          * @class   RCSException
41          * @brief    This class helps to throw wide range of exception to the application/developers.
42          *               It inherits the standard exception class.
43          *
44          */
45         class RCSException: public std::exception
46         {
47             public:
48                 /**
49                 * Default Constructor
50                 */
51                 RCSException();
52
53                 /**
54                 * Parametrized Constructor  to set exception description as a string.
55                 *
56                 * @param what - exception description
57                 */
58                 explicit RCSException(const std::string &what);
59
60                 /**
61                 * Parametrized Constructor  to set exception description as a string.
62                 *
63                 * @param what - exception description
64                 */
65                 explicit RCSException(std::string &&what);
66
67                 /**
68                 * virtual destructor
69                 */
70                 virtual ~RCSException() noexcept {}
71
72                 /**
73                 * API for returning the exception description in string format
74                 *
75                 * @return  const char* - exception description
76                 */
77                 virtual const char *what() const noexcept;
78
79             private:
80                 /**
81                  *  Exception description
82                  */
83                 std::string m_what;
84         };
85
86         /**
87          * @class   PlatformException
88          * @brief   This class helps in throwing platform exception to the application/developers.
89          *              It inherits from RCSException class.
90          *
91          * NOTE: OCStackResult is defined in octypes.h.
92          */
93         class PlatformException: public RCSException
94         {
95             public:
96                 explicit PlatformException(OCStackResult reason);
97
98                 /**
99                  * API for getting exception code.
100                  *
101                  * @return  OCStackResult - exception code.
102                  *
103                  */
104                 OCStackResult getReasonCode() const;
105                 /**
106                  * API for getting exception reason.
107                  *
108                  * @return string - exception reason as a string.
109                  *
110                  */
111                 std::string getReason() const;
112
113             private:
114                 /*
115                 * reason for the exception, stored as OCStackResult value.
116                 */
117                 OCStackResult m_reason;
118         };
119     }
120 }
121
122 #endif // RES_ENCAPSULATION_RCSEXCEPTION_H