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