1 /***************************************************************************
2 * Copyright (C) 2006 by Gerd v. Egidy *
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. *
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. *
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
25 #include <boost/serialization/export.hpp>
26 #include <boost/serialization/tracking.hpp>
28 // serialization for std::exception
30 namespace serialization {
32 template<class Archive>
33 void serialize(Archive & ar, std::exception & g, const unsigned int version)
37 } // namespace serialization
43 // a generic exception that can be handeled with libt2n
44 class t2n_exception : public std::exception
49 friend class boost::serialization::access;
50 template<class Archive>
51 void serialize(Archive & ar, const unsigned int version)
53 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(exception);
54 ar & BOOST_SERIALIZATION_NVP(message);
58 t2n_exception(const string& _message)
64 virtual const char* what() const throw()
65 { return message.c_str(); }
67 virtual t2n_exception* clone() const
68 { return new t2n_exception(*this); }
70 virtual ~t2n_exception() throw()
73 virtual void do_throw()
76 BOOST_CLASS_EXPORT(t2n_exception)
78 // a (unspecified) problem with libt2n communication
79 class t2n_communication_error : public t2n_exception
82 friend class boost::serialization::access;
83 template<class Archive>
84 void serialize(Archive & ar, const unsigned int version)
86 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
90 t2n_communication_error(const string& _message)
91 : t2n_exception(_message)
94 t2n_communication_error()
97 ipc_exception* clone() const
98 { return new t2n_communication_error(*this); }
103 BOOST_CLASS_EXPORT(t2n_communication_error)
105 // can't connect to libt2n server
106 class t2n_connect_error : public t2n_communication_error
109 friend class boost::serialization::access;
110 template<class Archive>
111 void serialize(Archive & ar, const unsigned int version)
113 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
117 t2n_connect_error(const string& _message)
118 : t2n_communication_error(_message)
124 ipc_exception* clone() const
125 { return new t2n_connect_error(*this); }
130 BOOST_CLASS_EXPORT(t2n_connect_error)
132 // error establishing a socket on the server (only thrown on the server-side)
133 class t2n_server_error : public t2n_communication_error
136 friend class boost::serialization::access;
137 template<class Archive>
138 void serialize(Archive & ar, const unsigned int version)
140 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
144 t2n_server_error(const string& _message)
145 : t2n_communication_error(_message)
151 ipc_exception* clone() const
152 { return new t2n_server_error(*this); }
157 BOOST_CLASS_EXPORT(t2n_server_error)
159 // error transmitting or receiving libt2n messages
160 class t2n_transfer_error : public t2n_communication_error
163 friend class boost::serialization::access;
164 template<class Archive>
165 void serialize(Archive & ar, const unsigned int version)
167 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
171 t2n_transfer_error(const string& _message)
172 : t2n_communication_error(_message)
178 ipc_exception* clone() const
179 { return new t2n_transfer_error(*this); }
184 BOOST_CLASS_EXPORT(t2n_transfer_error)
186 // tried to talk to an incompatible libt2n version
187 class t2n_version_mismatch : public t2n_communication_error
190 friend class boost::serialization::access;
191 template<class Archive>
192 void serialize(Archive & ar, const unsigned int version)
194 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
198 t2n_version_mismatch(const string& _message)
199 : t2n_communication_error(_message)
202 t2n_version_mismatch()
205 ipc_exception* clone() const
206 { return new t2n_version_mismatch(*this); }
211 BOOST_CLASS_EXPORT(t2n_version_mismatch)
213 // illegal libt2n command received
214 class t2n_command_error : public t2n_exception
217 friend class boost::serialization::access;
218 template<class Archive>
219 void serialize(Archive & ar, const unsigned int version)
221 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
225 t2n_command_error(const string& _message)
226 : t2n_exception(_message)
232 ipc_exception* clone() const
233 { return new t2n_command_error(*this); }
238 BOOST_CLASS_EXPORT(t2n_command_error)
240 // error serializing or deserializing a libt2n command packet
241 class t2n_serialization_error : public t2n_exception
244 friend class boost::serialization::access;
245 template<class Archive>
246 void serialize(Archive & ar, const unsigned int version)
248 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
252 t2n_serialization_error(const string& _message)
253 : t2n_exception(_message)
256 t2n_serialization_error()
259 ipc_exception* clone() const
260 { return new t2n_serialization_error(*this); }
265 BOOST_CLASS_EXPORT(t2n_serialization_error)
267 // a runtime error within the remote function
268 // derive your own custom exceptions from this one
269 class t2n_runtime_error : public t2n_exception
272 friend class boost::serialization::access;
273 template<class Archive>
274 void serialize(Archive & ar, const unsigned int version)
276 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
280 t2n_runtime_error(const string& _message)
281 : t2n_exception(_message)
287 ipc_exception* clone() const
288 { return new t2n_runtime_error(*this); }
293 BOOST_CLASS_EXPORT(t2n_runtime_error)