libt2n: (tomj) make compilable again
[libt2n] / src / t2n_exception.hxx
... / ...
CommitLineData
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
25#include <boost/serialization/serialization.hpp>
26
27namespace boost {
28namespace serialization {
29
30// make std::exception serializable
31template<class Archive>
32void serialize(Archive & ar, std::exception & g, const unsigned int version)
33{
34}
35
36} // namespace serialization
37} // namespace boost
38
39namespace libt2n
40{
41/** @brief a generic exception that can be handeled with libt2n
42 @note don't derive the exceptions your application generates directly from this one
43 but use libt2n::t2n_runtime_error for this
44*/
45class t2n_exception : public std::exception
46{
47 private:
48 std::string message;
49
50 friend class boost::serialization::access;
51 template<class Archive>
52 void serialize(Archive & ar, const unsigned int version);
53
54 public:
55 t2n_exception(const std::string& _message)
56 { message=_message; }
57
58 t2n_exception()
59 { }
60
61 virtual const char* what() const throw()
62 { return message.c_str(); }
63
64 virtual t2n_exception* clone() const
65 { return new t2n_exception(*this); }
66
67 virtual ~t2n_exception() throw()
68 {}
69
70 virtual void do_throw()
71 { throw *this; }
72};
73
74/// a (unspecified) problem with libt2n communication
75class t2n_communication_error : public t2n_exception
76{
77 private:
78 friend class boost::serialization::access;
79 template<class Archive>
80 void serialize(Archive & ar, const unsigned int version);
81
82 public:
83 t2n_communication_error(const std::string& _message)
84 : t2n_exception(_message)
85 { }
86
87 t2n_communication_error()
88 { }
89
90 t2n_exception* clone() const
91 { return new t2n_communication_error(*this); }
92
93 void do_throw()
94 { throw *this; }
95};
96
97/// can't connect to libt2n server
98class t2n_connect_error : public t2n_communication_error
99{
100 private:
101 friend class boost::serialization::access;
102 template<class Archive>
103 void serialize(Archive & ar, const unsigned int version);
104
105 public:
106 t2n_connect_error(const std::string& _message)
107 : t2n_communication_error(_message)
108 { }
109
110 t2n_connect_error()
111 { }
112
113 t2n_exception* clone() const
114 { return new t2n_connect_error(*this); }
115
116 void do_throw()
117 { throw *this; }
118};
119
120/// error establishing a socket on the server (only thrown on the server-side)
121class t2n_server_error : public t2n_communication_error
122{
123 private:
124 friend class boost::serialization::access;
125 template<class Archive>
126 void serialize(Archive & ar, const unsigned int version);
127
128 public:
129 t2n_server_error(const std::string& _message)
130 : t2n_communication_error(_message)
131 { }
132
133 t2n_server_error()
134 { }
135
136 t2n_exception* clone() const
137 { return new t2n_server_error(*this); }
138
139 void do_throw()
140 { throw *this; }
141};
142
143/// error transmitting or receiving libt2n messages
144class t2n_transfer_error : public t2n_communication_error
145{
146 private:
147 friend class boost::serialization::access;
148 template<class Archive>
149 void serialize(Archive & ar, const unsigned int version);
150
151 public:
152 t2n_transfer_error(const std::string& _message)
153 : t2n_communication_error(_message)
154 { }
155
156 t2n_transfer_error()
157 { }
158
159 t2n_exception* clone() const
160 { return new t2n_transfer_error(*this); }
161
162 void do_throw()
163 { throw *this; }
164};
165
166/// tried to talk to an incompatible libt2n version
167class t2n_version_mismatch : public t2n_communication_error
168{
169 private:
170 friend class boost::serialization::access;
171 template<class Archive>
172 void serialize(Archive & ar, const unsigned int version);
173
174 public:
175 t2n_version_mismatch(const std::string& _message)
176 : t2n_communication_error(_message)
177 { }
178
179 t2n_version_mismatch()
180 { }
181
182 t2n_exception* clone() const
183 { return new t2n_version_mismatch(*this); }
184
185 void do_throw()
186 { throw *this; }
187};
188
189/// illegal libt2n command received
190class t2n_command_error : public t2n_exception
191{
192 private:
193 friend class boost::serialization::access;
194 template<class Archive>
195 void serialize(Archive & ar, const unsigned int version);
196
197 public:
198 t2n_command_error(const std::string& _message)
199 : t2n_exception(_message)
200 { }
201
202 t2n_command_error()
203 { }
204
205 t2n_exception* clone() const
206 { return new t2n_command_error(*this); }
207
208 void do_throw()
209 { throw *this; }
210};
211
212/// error serializing or deserializing a libt2n command packet
213class t2n_serialization_error : public t2n_exception
214{
215 private:
216 friend class boost::serialization::access;
217 template<class Archive>
218 void serialize(Archive & ar, const unsigned int version);
219
220 public:
221 t2n_serialization_error(const std::string& _message)
222 : t2n_exception(_message)
223 { }
224
225 t2n_serialization_error()
226 { }
227
228 t2n_exception* clone() const
229 { return new t2n_serialization_error(*this); }
230
231 void do_throw()
232 { throw *this; }
233};
234
235/** @brief a runtime error within the remote function.
236 derive your own custom exceptions from this one
237
238 @note you must override the virtual clone method if you do so (used by libt2n::command_server::handle())
239*/
240class t2n_runtime_error : public t2n_exception
241{
242 private:
243 friend class boost::serialization::access;
244 template<class Archive>
245 void serialize(Archive & ar, const unsigned int version);
246
247 public:
248 t2n_runtime_error(const std::string& _message)
249 : t2n_exception(_message)
250 { }
251
252 t2n_runtime_error()
253 { }
254
255 t2n_exception* clone() const
256 { return new t2n_runtime_error(*this); }
257
258 void do_throw()
259 { throw *this; }
260};
261
262} // namespace libt2n
263
264#endif