tizen 2.4 release
[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 <string>
20 #include <dpl/exception.h>
21
22 namespace WrtDeviceApis {
23 namespace Commons {
24 #define PLUGINS_DECLARE_EXCEPTION_TYPE(BaseClass, Class)                       \
25     class Class : public BaseClass                                             \
26     {                                                                          \
27     public:                                                                    \
28         Class() = default;                                                     \
29                                                                                \
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                                                                                \
37         Class(const char *path,                                                \
38               const char *function,                                            \
39               int line,                                                        \
40               const DPL::Exception & reason,                                   \
41               const std::string & message = std::string()) :                   \
42             BaseClass(path, function, line, reason, message)                   \
43         { }                                                                    \
44                                                                                \
45         virtual ::WrtDeviceApis::Commons::ExceptionCodes::Enumeration getCode() const  \
46         {                                                                      \
47             return ::WrtDeviceApis::Commons::ExceptionCodes::Class;            \
48         }                                                                      \
49     };
50
51 class ExceptionCodes
52 {
53   public:
54     enum Enumeration
55     {
56         None,
57         Exception,
58         InvalidArgumentException,
59         ConversionException,
60         NullPointerException,
61         UnknownException,
62         PlatformException,
63         OutOfRangeException,
64         EventCancelledException,
65         EventWrongStateException,
66         SecurityException,
67         UnsupportedException,
68         PlatformWrongStateException,
69         PendingOperationException,
70         AlreadyInUseException,
71         CameraCaptureException,
72         CameraLiveVideoException,
73         LocalStorageValueNoModifableException,
74         NotFoundException
75     };
76 };
77
78 /**
79  * General exception.
80  */
81 PLUGINS_DECLARE_EXCEPTION_TYPE(DPL::Exception, Exception)
82
83 /**
84  * Thrown when passed argument is not of expected type.
85  */
86 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, InvalidArgumentException)
87
88 /**
89  * Thrown when type conversion is not possible.
90  */
91 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, ConversionException)
92
93 /**
94  * Thrown when trying to operate on an object which is set to NULL.
95  */
96 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, NullPointerException)
97
98 /**
99  * Thrown when unknown error occured.
100  */
101 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, UnknownException)
102
103 /**
104  * Thrown when platform function returned error code or threw an exception.
105  */
106 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, PlatformException)
107
108 /**
109  * Thrown when trying to access out of range element from array
110  */
111 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, OutOfRangeException)
112
113 /**
114  * Thrown when trying to operate on cancelled event
115  */
116 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, EventCancelledException)
117
118 /**
119  * Thrown when trying to operate on event in wrong state
120  */
121 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, EventWrongStateException)
122
123 /**
124  * Thrown when trying to perform some action w/o proper permissions.
125  */
126 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, SecurityException)
127
128 /**
129  * Thrown when trying to perform action that is not supported by current
130  * platform.
131  */
132 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, UnsupportedException)
133
134 /**
135  * Thrown when trying to perform action on platform in wrong state.
136  */
137 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, PlatformWrongStateException)
138
139 /**
140  * Thrown when trying to perform asynchronous action on JS object
141  * that already executes other asynchronous operation.
142  */
143 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, PendingOperationException)
144
145 /**
146  * Thrown when used camera is already in use.
147  */
148 PLUGINS_DECLARE_EXCEPTION_TYPE(Exception, AlreadyInUseException)
149
150 /**
151  * Thrown when unpredicted error occurs while a picture or video is being
152  * 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 } // WrtDeviceApisCommon
173
174 #endif /* WRTDEVICEAPIS_COMMONS_EXCEPTION_H_ */