1 | /* |
---|
2 | * Copyright (c) 2005, Eric Crahen |
---|
3 | * |
---|
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
5 | * of this software and associated documentation files (the "Software"), to deal |
---|
6 | * in the Software without restriction, including without limitation the rights |
---|
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
8 | * copies of the Software, and to permit persons to whom the Software is furnished |
---|
9 | * to do so, subject to the following conditions: |
---|
10 | * |
---|
11 | * The above copyright notice and this permission notice shall be included in all |
---|
12 | * copies or substantial portions of the Software. |
---|
13 | * |
---|
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
---|
18 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
---|
19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
---|
20 | * |
---|
21 | */ |
---|
22 | |
---|
23 | #ifndef __ZTEXCEPTIONS_H__ |
---|
24 | #define __ZTEXCEPTIONS_H__ |
---|
25 | |
---|
26 | |
---|
27 | #include "zthread/Config.h" |
---|
28 | #include <string> |
---|
29 | |
---|
30 | namespace ZThread { |
---|
31 | |
---|
32 | /** |
---|
33 | * @class Synchronization_Exception |
---|
34 | * |
---|
35 | * Serves as a general base class for the Exception hierarchy used within |
---|
36 | * this package. |
---|
37 | * |
---|
38 | */ |
---|
39 | class Synchronization_Exception { |
---|
40 | |
---|
41 | // Restrict heap allocation |
---|
42 | static void * operator new(size_t size); |
---|
43 | static void * operator new[](size_t size); |
---|
44 | |
---|
45 | std::string _msg; |
---|
46 | |
---|
47 | public: |
---|
48 | |
---|
49 | /** |
---|
50 | * Create a new exception with a default error message 'Synchronization |
---|
51 | * Exception' |
---|
52 | */ |
---|
53 | Synchronization_Exception() : _msg("Synchronization exception") { } |
---|
54 | |
---|
55 | /** |
---|
56 | * Create a new exception with a given error message |
---|
57 | * |
---|
58 | * @param const char* - error message |
---|
59 | */ |
---|
60 | Synchronization_Exception(const char* msg) : _msg(msg) { } |
---|
61 | |
---|
62 | /** |
---|
63 | * Get additional info about the exception |
---|
64 | * |
---|
65 | * @return const char* for the error message |
---|
66 | */ |
---|
67 | const char* what() const { |
---|
68 | return _msg.c_str(); |
---|
69 | } |
---|
70 | |
---|
71 | }; |
---|
72 | |
---|
73 | |
---|
74 | /** |
---|
75 | * @class Interrupted_Exception |
---|
76 | * |
---|
77 | * Used to describe an interrupted operation that would have normally |
---|
78 | * blocked the calling thread |
---|
79 | */ |
---|
80 | class Interrupted_Exception : public Synchronization_Exception { |
---|
81 | |
---|
82 | public: |
---|
83 | |
---|
84 | //! Create a new exception |
---|
85 | Interrupted_Exception() : Synchronization_Exception("Thread interrupted") { } |
---|
86 | |
---|
87 | //! Create a new exception |
---|
88 | Interrupted_Exception(const char* msg) : Synchronization_Exception(msg) { } |
---|
89 | |
---|
90 | }; |
---|
91 | |
---|
92 | |
---|
93 | |
---|
94 | /** |
---|
95 | * @class Deadlock_Exception |
---|
96 | * |
---|
97 | * Thrown when deadlock has been detected |
---|
98 | */ |
---|
99 | class Deadlock_Exception : public Synchronization_Exception { |
---|
100 | public: |
---|
101 | |
---|
102 | //! Create a new exception |
---|
103 | Deadlock_Exception() : Synchronization_Exception("Deadlock detected") { } |
---|
104 | |
---|
105 | //! Create a new exception |
---|
106 | Deadlock_Exception(const char* msg) : Synchronization_Exception(msg) { } |
---|
107 | |
---|
108 | }; |
---|
109 | |
---|
110 | |
---|
111 | /** |
---|
112 | * @class InvalidOp_Exception |
---|
113 | * |
---|
114 | * Thrown when performing an illegal operation this object |
---|
115 | */ |
---|
116 | class InvalidOp_Exception : public Synchronization_Exception { |
---|
117 | public: |
---|
118 | |
---|
119 | //! Create a new exception |
---|
120 | InvalidOp_Exception() : Synchronization_Exception("Invalid operation") { } |
---|
121 | //! Create a new exception |
---|
122 | InvalidOp_Exception(const char* msg) : Synchronization_Exception(msg) { } |
---|
123 | |
---|
124 | }; |
---|
125 | |
---|
126 | |
---|
127 | |
---|
128 | /** |
---|
129 | * @class Initialization_Exception |
---|
130 | * |
---|
131 | * Thrown when the system has no more resources to create new |
---|
132 | * synchronization controls |
---|
133 | */ |
---|
134 | class Initialization_Exception : public Synchronization_Exception { |
---|
135 | |
---|
136 | public: |
---|
137 | |
---|
138 | //! Create a new exception |
---|
139 | Initialization_Exception() : Synchronization_Exception("Initialization error") { } |
---|
140 | //! Create a new exception |
---|
141 | Initialization_Exception(const char*msg) : Synchronization_Exception(msg) { } |
---|
142 | |
---|
143 | }; |
---|
144 | |
---|
145 | /** |
---|
146 | * @class Cancellation_Exception |
---|
147 | * |
---|
148 | * Cancellation_Exceptions are thrown by 'Canceled' objects. |
---|
149 | * @see Cancelable |
---|
150 | */ |
---|
151 | class Cancellation_Exception : public Synchronization_Exception { |
---|
152 | |
---|
153 | public: |
---|
154 | |
---|
155 | //! Create a new Cancelltion_Exception |
---|
156 | Cancellation_Exception() : Synchronization_Exception("Canceled") { } |
---|
157 | //! Create a new Cancelltion_Exception |
---|
158 | Cancellation_Exception(const char*msg) : Synchronization_Exception(msg) { } |
---|
159 | |
---|
160 | }; |
---|
161 | |
---|
162 | |
---|
163 | /** |
---|
164 | * @class Timeout_Exception |
---|
165 | * |
---|
166 | * There is no need for error messaged simply indicates the last |
---|
167 | * operation timed out |
---|
168 | */ |
---|
169 | class Timeout_Exception : public Synchronization_Exception { |
---|
170 | public: |
---|
171 | |
---|
172 | //! Create a new Timeout_Exception |
---|
173 | Timeout_Exception() : Synchronization_Exception("Timeout") { } |
---|
174 | //! Create a new |
---|
175 | Timeout_Exception(const char*msg) : Synchronization_Exception(msg) { } |
---|
176 | |
---|
177 | }; |
---|
178 | |
---|
179 | /** |
---|
180 | * @class NoSuchElement_Exception |
---|
181 | * |
---|
182 | * The last operation that was attempted on a Queue could not find |
---|
183 | * the item that was indicated (during that last Queue method invocation) |
---|
184 | */ |
---|
185 | class NoSuchElement_Exception { |
---|
186 | public: |
---|
187 | |
---|
188 | //! Create a new exception |
---|
189 | NoSuchElement_Exception() {} |
---|
190 | |
---|
191 | }; |
---|
192 | |
---|
193 | /** |
---|
194 | * @class InvalidTask_Exception |
---|
195 | * |
---|
196 | * Thrown when a task is not valid (e.g. null or start()ing a thread with |
---|
197 | * no overriden run() method) |
---|
198 | */ |
---|
199 | class InvalidTask_Exception : public InvalidOp_Exception { |
---|
200 | public: |
---|
201 | |
---|
202 | //! Create a new exception |
---|
203 | InvalidTask_Exception() : InvalidOp_Exception("Invalid task") {} |
---|
204 | |
---|
205 | }; |
---|
206 | |
---|
207 | /** |
---|
208 | * @class BrokenBarrier_Exception |
---|
209 | * |
---|
210 | * Thrown when a Barrier is broken because one of the participating threads |
---|
211 | * has been interrupted. |
---|
212 | */ |
---|
213 | class BrokenBarrier_Exception : public Synchronization_Exception { |
---|
214 | |
---|
215 | public: |
---|
216 | |
---|
217 | //! Create a new exception |
---|
218 | BrokenBarrier_Exception() : Synchronization_Exception("Barrier broken") { } |
---|
219 | |
---|
220 | //! Create a new exception |
---|
221 | BrokenBarrier_Exception(const char* msg) : Synchronization_Exception(msg) { } |
---|
222 | |
---|
223 | }; |
---|
224 | |
---|
225 | /** |
---|
226 | * @class Future_Exception |
---|
227 | * |
---|
228 | * Thrown when there is an error using a Future. |
---|
229 | */ |
---|
230 | class Future_Exception : public Synchronization_Exception { |
---|
231 | |
---|
232 | public: |
---|
233 | |
---|
234 | //! Create a new exception |
---|
235 | Future_Exception() : Synchronization_Exception() { } |
---|
236 | |
---|
237 | //! Create a new exception |
---|
238 | Future_Exception(const char* msg) : Synchronization_Exception(msg) { } |
---|
239 | |
---|
240 | }; |
---|
241 | |
---|
242 | }; |
---|
243 | |
---|
244 | #endif // __ZTEXCEPTIONS_H__ |
---|