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>
29 namespace serialization {
31 // make std::exception serializable
32 template<class Archive>
33 void serialize(Archive & ar, std::exception & g, const unsigned int version)
37 } // namespace serialization
42 /// a generic exception that can be handeled with libt2n
43 class t2n_exception : public std::exception
48 friend class boost::serialization::access;
49 template<class Archive>
50 void serialize(Archive & ar, const unsigned int version)
52 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(exception);
53 ar & BOOST_SERIALIZATION_NVP(message);
57 t2n_exception(const std::string& _message)
63 virtual const char* what() const throw()
64 { return message.c_str(); }
66 virtual t2n_exception* clone() const
67 { return new t2n_exception(*this); }
69 virtual ~t2n_exception() throw()
72 virtual void do_throw()
76 /// a (unspecified) problem with libt2n communication
77 class t2n_communication_error : public t2n_exception
80 friend class boost::serialization::access;
81 template<class Archive>
82 void serialize(Archive & ar, const unsigned int version)
84 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
88 t2n_communication_error(const std::string& _message)
89 : t2n_exception(_message)
92 t2n_communication_error()
95 t2n_exception* clone() const
96 { return new t2n_communication_error(*this); }
102 /// can't connect to libt2n server
103 class t2n_connect_error : public t2n_communication_error
106 friend class boost::serialization::access;
107 template<class Archive>
108 void serialize(Archive & ar, const unsigned int version)
110 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
114 t2n_connect_error(const std::string& _message)
115 : t2n_communication_error(_message)
121 t2n_exception* clone() const
122 { return new t2n_connect_error(*this); }
128 /// error establishing a socket on the server (only thrown on the server-side)
129 class t2n_server_error : public t2n_communication_error
132 friend class boost::serialization::access;
133 template<class Archive>
134 void serialize(Archive & ar, const unsigned int version)
136 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
140 t2n_server_error(const std::string& _message)
141 : t2n_communication_error(_message)
147 t2n_exception* clone() const
148 { return new t2n_server_error(*this); }
154 /// error transmitting or receiving libt2n messages
155 class t2n_transfer_error : public t2n_communication_error
158 friend class boost::serialization::access;
159 template<class Archive>
160 void serialize(Archive & ar, const unsigned int version)
162 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
166 t2n_transfer_error(const std::string& _message)
167 : t2n_communication_error(_message)
173 t2n_exception* clone() const
174 { return new t2n_transfer_error(*this); }
180 /// tried to talk to an incompatible libt2n version
181 class t2n_version_mismatch : public t2n_communication_error
184 friend class boost::serialization::access;
185 template<class Archive>
186 void serialize(Archive & ar, const unsigned int version)
188 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
192 t2n_version_mismatch(const std::string& _message)
193 : t2n_communication_error(_message)
196 t2n_version_mismatch()
199 t2n_exception* clone() const
200 { return new t2n_version_mismatch(*this); }
206 /// illegal libt2n command received
207 class t2n_command_error : public t2n_exception
210 friend class boost::serialization::access;
211 template<class Archive>
212 void serialize(Archive & ar, const unsigned int version)
214 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
218 t2n_command_error(const std::string& _message)
219 : t2n_exception(_message)
225 t2n_exception* clone() const
226 { return new t2n_command_error(*this); }
232 /// error serializing or deserializing a libt2n command packet
233 class t2n_serialization_error : public t2n_exception
236 friend class boost::serialization::access;
237 template<class Archive>
238 void serialize(Archive & ar, const unsigned int version)
240 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
244 t2n_serialization_error(const std::string& _message)
245 : t2n_exception(_message)
248 t2n_serialization_error()
251 t2n_exception* clone() const
252 { return new t2n_serialization_error(*this); }
258 /** @brief a runtime error within the remote function.
259 derive your own custom exceptions from this one
261 class t2n_runtime_error : public t2n_exception
264 friend class boost::serialization::access;
265 template<class Archive>
266 void serialize(Archive & ar, const unsigned int version)
268 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
272 t2n_runtime_error(const std::string& _message)
273 : t2n_exception(_message)
279 t2n_exception* clone() const
280 { return new t2n_runtime_error(*this); }
286 } // namespace libt2n