aa1f3b663eac1343aeb924150f95c2a56d18002b
[platform/framework/web/wrt-plugins-common.git] / src / Commons / Exception.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 #ifndef WRTDEVICEAPIS_COMMONS_EXCEPTION_H_
17 #define WRTDEVICEAPIS_COMMONS_EXCEPTION_H_
18
19 #include <dpl/exception.h>
20
21 namespace WrtDeviceApis {
22 namespace Commons {
23
24 #define PLUGINS_DECLARE_EXCEPTION_TYPE(BaseClass, Class) \
25     class Class :       \
26         public BaseClass \
27     { \
28         ExceptionCodes::Enumeration m_code; \
29       public: \
30         virtual ExceptionCodes::Enumeration getCode() const { return m_code; } \
31         Class(const char *path, \
32               const char *function, \
33               int line, \
34               const std::string & message = std::string()) :                                                                                               \
35                       BaseClass(path, function, line, message) \
36               { \
37                   BaseClass::m_className = # Class; \
38                   m_code = ExceptionCodes::Class; \
39               } \
40  \
41               Class(const char *path, \
42                     const char *function, \
43                     int line, \
44                     const DPL::Exception & reason, \
45                     const std::string & message = std::string()) :                                                                                                                             \
46                             BaseClass(path, function, line, reason, message) \
47                     { \
48                         BaseClass::m_className = # Class; \
49                         m_code = ExceptionCodes::Class; \
50                     } \
51                     };
52
53 class ExceptionCodes
54 {
55   public:
56     enum Enumeration
57     {
58         None,
59         Exception,
60         InvalidArgumentException,
61         ConversionException,
62         NullPointerException,
63         UnknownException,
64         PlatformException,
65         OutOfRangeException,
66         EventCancelledException,
67         EventWrongStateException,
68         SecurityException,
69         UnsupportedException,
70         PlatformWrongStateException,
71         PendingOperationException,
72         AlreadyInUseException,
73         CameraCaptureException,
74         CameraLiveVideoException,
75         LocalStorageValueNoModifableException,
76         NotFoundException
77     };
78 };
79
80 /**
81  * General exception.
82  */
83 PLUGINS_DECLARE_EXCEPTION_TYPE(DPL::Exception, Exception)
84
85 /**
86  * Thrown when passed argument is not of expected type.
87  */
88 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, InvalidArgumentException)
89
90 /**
91  * Thrown when type conversion is not possible.
92  */
93 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, ConversionException)
94
95 /**
96  * Thrown when trying to operate on an object which is set to NULL.
97  */
98 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, NullPointerException)
99
100 /**
101  * Thrown when unknown error occured.
102  */
103 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, UnknownException)
104
105 /**
106  * Thrown when platform function returned error code or threw an exception.
107  */
108 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, PlatformException)
109
110 /**
111  * Thrown when trying to access out of range element from array
112  */
113 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, OutOfRangeException)
114
115 /**
116  * Thrown when trying to operate on cancelled event
117  */
118 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, EventCancelledException)
119
120 /**
121  * Thrown when trying to operate on event in wrong state
122  */
123 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, EventWrongStateException)
124
125 /**
126  * Thrown when trying to perform some action w/o proper permissions.
127  */
128 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, SecurityException)
129
130 /**
131  * Thrown when trying to perform action that is not supported by current platform.
132  */
133 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, UnsupportedException)
134
135 /**
136  * Thrown when trying to perform action on platform in wrong state.
137  */
138 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, PlatformWrongStateException)
139
140 /**
141  * Thrown when trying to perform asynchronous action on JS object
142  * that already executes other asynchronous operation.
143  */
144 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, PendingOperationException)
145
146 /**
147  * Thrown when used camera is already in use.
148  */
149 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, AlreadyInUseException)
150
151 /**
152  * Thrown when unpredicted error occurs while a picture or video is being captured
153  * or if endRecording is called while no video is currently captured.
154  */
155 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, CameraCaptureException)
156
157 /**
158  * camera live video cannot be provided.
159  */
160 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, CameraLiveVideoException)
161
162 /**
163  * Error trying to modify read only value
164  */
165 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, LocalStorageValueNoModifableException)
166
167 /**
168  * Thrown when object is not found.
169  */
170 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, NotFoundException)
171
172 }
173 } // WrtDeviceApisCommon
174
175 #endif /* WRTDEVICEAPIS_COMMONS_EXCEPTION_H_ */