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/serialization.hpp>
26 #include <boost/serialization/export.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
44 generic libt2n exception
46 // a generic exception that can be handeled with libt2n
47 class t2n_exception : public std::exception
52 friend class boost::serialization::access;
53 template<class Archive>
54 void serialize(Archive & ar, const unsigned int version)
56 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(exception);
57 ar & BOOST_SERIALIZATION_NVP(message);
61 t2n_exception(const std::string& _message)
67 virtual const char* what() const throw()
68 { return message.c_str(); }
70 virtual t2n_exception* clone() const
71 { return new t2n_exception(*this); }
73 virtual ~t2n_exception() throw()
76 virtual void do_throw()
79 BOOST_CLASS_EXPORT(t2n_exception)
81 // a (unspecified) problem with libt2n communication
82 class t2n_communication_error : public t2n_exception
85 friend class boost::serialization::access;
86 template<class Archive>
87 void serialize(Archive & ar, const unsigned int version)
89 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
93 t2n_communication_error(const std::string& _message)
94 : t2n_exception(_message)
97 t2n_communication_error()
100 t2n_exception* clone() const
101 { return new t2n_communication_error(*this); }
106 BOOST_CLASS_EXPORT(t2n_communication_error)
108 // can't connect to libt2n server
109 class t2n_connect_error : public t2n_communication_error
112 friend class boost::serialization::access;
113 template<class Archive>
114 void serialize(Archive & ar, const unsigned int version)
116 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
120 t2n_connect_error(const std::string& _message)
121 : t2n_communication_error(_message)
127 t2n_exception* clone() const
128 { return new t2n_connect_error(*this); }
133 BOOST_CLASS_EXPORT(t2n_connect_error)
135 // error establishing a socket on the server (only thrown on the server-side)
136 class t2n_server_error : public t2n_communication_error
139 friend class boost::serialization::access;
140 template<class Archive>
141 void serialize(Archive & ar, const unsigned int version)
143 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
147 t2n_server_error(const std::string& _message)
148 : t2n_communication_error(_message)
154 t2n_exception* clone() const
155 { return new t2n_server_error(*this); }
160 BOOST_CLASS_EXPORT(t2n_server_error)
162 // error transmitting or receiving libt2n messages
163 class t2n_transfer_error : public t2n_communication_error
166 friend class boost::serialization::access;
167 template<class Archive>
168 void serialize(Archive & ar, const unsigned int version)
170 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
174 t2n_transfer_error(const std::string& _message)
175 : t2n_communication_error(_message)
181 t2n_exception* clone() const
182 { return new t2n_transfer_error(*this); }
187 BOOST_CLASS_EXPORT(t2n_transfer_error)
189 // tried to talk to an incompatible libt2n version
190 class t2n_version_mismatch : public t2n_communication_error
193 friend class boost::serialization::access;
194 template<class Archive>
195 void serialize(Archive & ar, const unsigned int version)
197 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
201 t2n_version_mismatch(const std::string& _message)
202 : t2n_communication_error(_message)
205 t2n_version_mismatch()
208 t2n_exception* clone() const
209 { return new t2n_version_mismatch(*this); }
214 BOOST_CLASS_EXPORT(t2n_version_mismatch)
216 // illegal libt2n command received
217 class t2n_command_error : public t2n_exception
220 friend class boost::serialization::access;
221 template<class Archive>
222 void serialize(Archive & ar, const unsigned int version)
224 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
228 t2n_command_error(const std::string& _message)
229 : t2n_exception(_message)
235 t2n_exception* clone() const
236 { return new t2n_command_error(*this); }
241 BOOST_CLASS_EXPORT(t2n_command_error)
243 // error serializing or deserializing a libt2n command packet
244 class t2n_serialization_error : public t2n_exception
247 friend class boost::serialization::access;
248 template<class Archive>
249 void serialize(Archive & ar, const unsigned int version)
251 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
255 t2n_serialization_error(const std::string& _message)
256 : t2n_exception(_message)
259 t2n_serialization_error()
262 t2n_exception* clone() const
263 { return new t2n_serialization_error(*this); }
268 BOOST_CLASS_EXPORT(t2n_serialization_error)
270 // a runtime error within the remote function
271 // derive your own custom exceptions from this one
272 class t2n_runtime_error : public t2n_exception
275 friend class boost::serialization::access;
276 template<class Archive>
277 void serialize(Archive & ar, const unsigned int version)
279 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
283 t2n_runtime_error(const std::string& _message)
284 : t2n_exception(_message)
290 t2n_exception* clone() const
291 { return new t2n_runtime_error(*this); }
296 BOOST_CLASS_EXPORT(t2n_runtime_error)