Initialize Tizen 2.3
[framework/web/wrt-plugins-common.git] / src_wearable / 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 #define PLUGINS_DECLARE_EXCEPTION_TYPE(BaseClass, Class) \
24     class Class :       \
25         public BaseClass \
26     { \
27         ExceptionCodes::Enumeration m_code; \
28       public: \
29         virtual ExceptionCodes::Enumeration getCode() const { return m_code; } \
30         Class(const char *path, \
31               const char *function, \
32               int line, \
33               const std::string & message = std::string()) :                                                                                               \
34             BaseClass(path, function, line, message) \
35         { \
36             BaseClass::m_className = #Class; \
37             m_code = ExceptionCodes::Class; \
38         } \
39  \
40         Class(const char *path, \
41               const char *function, \
42               int line, \
43               const DPL::Exception & reason, \
44               const std::string & message = std::string()) :                                                                                                                             \
45             BaseClass(path, function, line, reason, message) \
46         { \
47             BaseClass::m_className = #Class; \
48             m_code = ExceptionCodes::Class; \
49         } \
50     };
51
52 class ExceptionCodes
53 {
54   public:
55     enum Enumeration
56     {
57         None,
58         Exception,
59         InvalidArgumentException,
60         ConversionException,
61         NullPointerException,
62         UnknownException,
63         PlatformException,
64         OutOfRangeException,
65         EventCancelledException,
66         EventWrongStateException,
67         SecurityException,
68         UnsupportedException,
69         PlatformWrongStateException,
70         PendingOperationException,
71         AlreadyInUseException,
72         CameraCaptureException,
73         CameraLiveVideoException,
74         LocalStorageValueNoModifableException,
75         NotFoundException
76     };
77 };
78
79 /**
80  * General exception.
81  */
82 PLUGINS_DECLARE_EXCEPTION_TYPE(DPL::Exception, Exception)
83
84 /**
85  * Thrown when passed argument is not of expected type.
86  */
87 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, InvalidArgumentException)
88
89 /**
90  * Thrown when type conversion is not possible.
91  */
92 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, ConversionException)
93
94 /**
95  * Thrown when trying to operate on an object which is set to NULL.
96  */
97 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, NullPointerException)
98
99 /**
100  * Thrown when unknown error occured.
101  */
102 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, UnknownException)
103
104 /**
105  * Thrown when platform function returned error code or threw an exception.
106  */
107 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, PlatformException)
108
109 /**
110  * Thrown when trying to access out of range element from array
111  */
112 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, OutOfRangeException)
113
114 /**
115  * Thrown when trying to operate on cancelled event
116  */
117 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, EventCancelledException)
118
119 /**
120  * Thrown when trying to operate on event in wrong state
121  */
122 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, EventWrongStateException)
123
124 /**
125  * Thrown when trying to perform some action w/o proper permissions.
126  */
127 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, SecurityException)
128
129 /**
130  * Thrown when trying to perform action that is not supported by current
131  * 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
153  * captured
154  * or if endRecording is called while no video is currently captured.
155  */
156 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, CameraCaptureException)
157
158 /**
159  * camera live video cannot be provided.
160  */
161 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, CameraLiveVideoException)
162
163 /**
164  * Error trying to modify read only value
165  */
166 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, LocalStorageValueNoModifableException)
167
168 /**
169  * Thrown when object is not found.
170  */
171 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, NotFoundException)
172 }
173 } // WrtDeviceApisCommon
174
175 #endif /* WRTDEVICEAPIS_COMMONS_EXCEPTION_H_ */