libt2n: (tomj) doxygen support
[libt2n] / src / t2n_exception.hxx
CommitLineData
ac7fdc22
GE
1/***************************************************************************
2 * Copyright (C) 2006 by Gerd v. Egidy *
3 * gve@intra2net.com *
4 * *
5 * This library is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU Lesser General Public License version *
7 * 2.1 as published by the Free Software Foundation. *
8 * *
9 * This library is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
19#ifndef __LIBT2N_T2N_EXCEPTION
20#define __LIBT2N_T2N_EXCEPTION
21
22#include <stdexcept>
23#include <string>
24
0cf4dc9b 25#include <boost/serialization/serialization.hpp>
ac7fdc22 26#include <boost/serialization/export.hpp>
ac7fdc22
GE
27
28// serialization for std::exception
29namespace boost {
30namespace serialization {
31
32template<class Archive>
33void serialize(Archive & ar, std::exception & g, const unsigned int version)
34{
35}
36
37} // namespace serialization
38} // namespace boost
39
40namespace libt2n
41{
42
59adb9e2
TJ
43/**
44 generic libt2n exception
45*/
ac7fdc22
GE
46// a generic exception that can be handeled with libt2n
47class t2n_exception : public std::exception
48{
49 private:
0cf4dc9b 50 std::string message;
ac7fdc22
GE
51
52 friend class boost::serialization::access;
53 template<class Archive>
54 void serialize(Archive & ar, const unsigned int version)
55 {
56 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(exception);
57 ar & BOOST_SERIALIZATION_NVP(message);
58 }
59
60 public:
0cf4dc9b 61 t2n_exception(const std::string& _message)
ac7fdc22
GE
62 { message=_message; }
63
64 t2n_exception()
65 { }
66
67 virtual const char* what() const throw()
68 { return message.c_str(); }
69
70 virtual t2n_exception* clone() const
71 { return new t2n_exception(*this); }
72
73 virtual ~t2n_exception() throw()
74 {}
75
76 virtual void do_throw()
77 { throw *this; }
78};
79BOOST_CLASS_EXPORT(t2n_exception)
80
81// a (unspecified) problem with libt2n communication
82class t2n_communication_error : public t2n_exception
83{
84 private:
85 friend class boost::serialization::access;
86 template<class Archive>
87 void serialize(Archive & ar, const unsigned int version)
88 {
89 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
90 }
91
92 public:
0cf4dc9b 93 t2n_communication_error(const std::string& _message)
ac7fdc22
GE
94 : t2n_exception(_message)
95 { }
96
97 t2n_communication_error()
98 { }
99
0cf4dc9b 100 t2n_exception* clone() const
ac7fdc22
GE
101 { return new t2n_communication_error(*this); }
102
103 void do_throw()
104 { throw *this; }
105};
106BOOST_CLASS_EXPORT(t2n_communication_error)
107
108// can't connect to libt2n server
109class t2n_connect_error : public t2n_communication_error
110{
111 private:
112 friend class boost::serialization::access;
113 template<class Archive>
114 void serialize(Archive & ar, const unsigned int version)
115 {
116 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
117 }
118
119 public:
0cf4dc9b 120 t2n_connect_error(const std::string& _message)
ac7fdc22
GE
121 : t2n_communication_error(_message)
122 { }
123
124 t2n_connect_error()
125 { }
126
0cf4dc9b 127 t2n_exception* clone() const
ac7fdc22
GE
128 { return new t2n_connect_error(*this); }
129
130 void do_throw()
131 { throw *this; }
132};
133BOOST_CLASS_EXPORT(t2n_connect_error)
134
135// error establishing a socket on the server (only thrown on the server-side)
136class t2n_server_error : public t2n_communication_error
137{
138 private:
139 friend class boost::serialization::access;
140 template<class Archive>
141 void serialize(Archive & ar, const unsigned int version)
142 {
143 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
144 }
145
146 public:
0cf4dc9b 147 t2n_server_error(const std::string& _message)
ac7fdc22
GE
148 : t2n_communication_error(_message)
149 { }
150
151 t2n_server_error()
152 { }
153
0cf4dc9b 154 t2n_exception* clone() const
ac7fdc22
GE
155 { return new t2n_server_error(*this); }
156
157 void do_throw()
158 { throw *this; }
159};
160BOOST_CLASS_EXPORT(t2n_server_error)
161
162// error transmitting or receiving libt2n messages
163class t2n_transfer_error : public t2n_communication_error
164{
165 private:
166 friend class boost::serialization::access;
167 template<class Archive>
168 void serialize(Archive & ar, const unsigned int version)
169 {
170 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
171 }
172
173 public:
0cf4dc9b 174 t2n_transfer_error(const std::string& _message)
ac7fdc22
GE
175 : t2n_communication_error(_message)
176 { }
177
178 t2n_transfer_error()
179 { }
180
0cf4dc9b 181 t2n_exception* clone() const
ac7fdc22
GE
182 { return new t2n_transfer_error(*this); }
183
184 void do_throw()
185 { throw *this; }
186};
187BOOST_CLASS_EXPORT(t2n_transfer_error)
188
189// tried to talk to an incompatible libt2n version
190class t2n_version_mismatch : public t2n_communication_error
191{
192 private:
193 friend class boost::serialization::access;
194 template<class Archive>
195 void serialize(Archive & ar, const unsigned int version)
196 {
197 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
198 }
199
200 public:
0cf4dc9b 201 t2n_version_mismatch(const std::string& _message)
ac7fdc22
GE
202 : t2n_communication_error(_message)
203 { }
204
205 t2n_version_mismatch()
206 { }
207
0cf4dc9b 208 t2n_exception* clone() const
ac7fdc22
GE
209 { return new t2n_version_mismatch(*this); }
210
211 void do_throw()
212 { throw *this; }
213};
214BOOST_CLASS_EXPORT(t2n_version_mismatch)
215
216// illegal libt2n command received
217class t2n_command_error : public t2n_exception
218{
219 private:
220 friend class boost::serialization::access;
221 template<class Archive>
222 void serialize(Archive & ar, const unsigned int version)
223 {
224 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
225 }
226
227 public:
0cf4dc9b 228 t2n_command_error(const std::string& _message)
ac7fdc22
GE
229 : t2n_exception(_message)
230 { }
231
232 t2n_command_error()
233 { }
234
0cf4dc9b 235 t2n_exception* clone() const
ac7fdc22
GE
236 { return new t2n_command_error(*this); }
237
238 void do_throw()
239 { throw *this; }
240};
241BOOST_CLASS_EXPORT(t2n_command_error)
242
243// error serializing or deserializing a libt2n command packet
244class t2n_serialization_error : public t2n_exception
245{
246 private:
247 friend class boost::serialization::access;
248 template<class Archive>
249 void serialize(Archive & ar, const unsigned int version)
250 {
251 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
252 }
253
254 public:
0cf4dc9b 255 t2n_serialization_error(const std::string& _message)
ac7fdc22
GE
256 : t2n_exception(_message)
257 { }
258
259 t2n_serialization_error()
260 { }
261
0cf4dc9b 262 t2n_exception* clone() const
ac7fdc22
GE
263 { return new t2n_serialization_error(*this); }
264
265 void do_throw()
266 { throw *this; }
267};
268BOOST_CLASS_EXPORT(t2n_serialization_error)
269
270// a runtime error within the remote function
271// derive your own custom exceptions from this one
272class t2n_runtime_error : public t2n_exception
273{
274 private:
275 friend class boost::serialization::access;
276 template<class Archive>
277 void serialize(Archive & ar, const unsigned int version)
278 {
279 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
280 }
281
282 public:
0cf4dc9b 283 t2n_runtime_error(const std::string& _message)
ac7fdc22
GE
284 : t2n_exception(_message)
285 { }
286
287 t2n_runtime_error()
288 { }
289
0cf4dc9b 290 t2n_exception* clone() const
ac7fdc22
GE
291 { return new t2n_runtime_error(*this); }
292
293 void do_throw()
294 { throw *this; }
295};
296BOOST_CLASS_EXPORT(t2n_runtime_error)
297
298}
299
300#endif