Merge "Patch 1 : Adding Arduino WiFi support. This requires updated Arduino WiFi...
[platform/upstream/iotivity.git] / include / OCException.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH 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 #ifndef __INTEL_OCEXCEPTION_H_2014_07_10
22  #define __INTEL_OCEXCEPTION_H_2014_07_10
23
24 #include <stdexcept>
25 #include <ocstack.h>
26 namespace OC {
27
28 typedef std::runtime_error reflection_exception;
29
30 class OCException : public std::runtime_error
31 {
32     public:
33         OCException(const std::string& msg, OCStackResult reason = OC_STACK_ERROR): std::runtime_error(msg),  m_reason(reason) {}
34         std::string reason()
35         {
36             switch(m_reason)
37             {
38                 case OC_STACK_OK:
39                     return "No Error";
40                 case OC_STACK_INVALID_URI:
41                     return "Invalid URI";
42                 case OC_STACK_INVALID_IP:
43                     return "Invalid IP";
44                 case OC_STACK_INVALID_PORT:
45                     return "Invalid Port";
46                 case OC_STACK_INVALID_CALLBACK:
47                     return "Invalid Callback";
48                 case OC_STACK_INVALID_METHOD:
49                     return "Invalid Method";
50                 case OC_STACK_INVALID_QUERY:
51                     return "Invalid Query";
52                 case OC_STACK_INVALID_PARAM:
53                     return "Invalid Param";
54                 case OC_STACK_INVALID_OBSERVE_PARAM:
55                     return "Invalid Observe Param";
56                 case OC_STACK_NO_MEMORY:
57                     return "No Memory";
58                 case OC_STACK_COMM_ERROR:
59                     return "Communication Error";
60                 case OC_STACK_NOTIMPL:
61                     return "Not Implemented";
62                 case OC_STACK_NO_RESOURCE:
63                     return "Resource Not Found";
64                 case OC_STACK_RESOURCE_ERROR:
65                     return "Resource Error";
66                 case OC_STACK_SLOW_RESOURCE:
67                     return "Slow Resource";
68                 case OC_STACK_NO_OBSERVERS:
69                     return "No Observers";
70                 case OC_STACK_ERROR:
71                     return "General Fault";
72                 default:
73                     return "Unknown Error";
74             }
75         }
76
77     private:
78         OCStackResult m_reason;
79 };
80
81 } // namespace OC
82
83 #endif