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>
28 namespace serialization {
30 // make std::exception serializable
31 template<class Archive>
32 void serialize(Archive & ar, std::exception & g, const unsigned int version)
36 } // namespace serialization
41 /// a generic exception that can be handeled with libt2n
42 class t2n_exception : public std::exception
47 friend class boost::serialization::access;
48 template<class Archive>
49 void serialize(Archive & ar, const unsigned int version)
51 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(exception);
52 ar & BOOST_SERIALIZATION_NVP(message);
56 t2n_exception(const std::string& _message)
62 virtual const char* what() const throw()
63 { return message.c_str(); }
65 virtual t2n_exception* clone() const
66 { return new t2n_exception(*this); }
68 virtual ~t2n_exception() throw()
71 virtual void do_throw()
75 /// a (unspecified) problem with libt2n communication
76 class t2n_communication_error : public t2n_exception
79 friend class boost::serialization::access;
80 template<class Archive>
81 void serialize(Archive & ar, const unsigned int version)
83 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
87 t2n_communication_error(const std::string& _message)
88 : t2n_exception(_message)
91 t2n_communication_error()
94 t2n_exception* clone() const
95 { return new t2n_communication_error(*this); }
101 /// can't connect to libt2n server
102 class t2n_connect_error : public t2n_communication_error
105 friend class boost::serialization::access;
106 template<class Archive>
107 void serialize(Archive & ar, const unsigned int version)
109 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
113 t2n_connect_error(const std::string& _message)
114 : t2n_communication_error(_message)
120 t2n_exception* clone() const
121 { return new t2n_connect_error(*this); }
127 /// error establishing a socket on the server (only thrown on the server-side)
128 class t2n_server_error : public t2n_communication_error
131 friend class boost::serialization::access;
132 template<class Archive>
133 void serialize(Archive & ar, const unsigned int version)
135 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
139 t2n_server_error(const std::string& _message)
140 : t2n_communication_error(_message)
146 t2n_exception* clone() const
147 { return new t2n_server_error(*this); }
153 /// error transmitting or receiving libt2n messages
154 class t2n_transfer_error : public t2n_communication_error
157 friend class boost::serialization::access;
158 template<class Archive>
159 void serialize(Archive & ar, const unsigned int version)
161 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
165 t2n_transfer_error(const std::string& _message)
166 : t2n_communication_error(_message)
172 t2n_exception* clone() const
173 { return new t2n_transfer_error(*this); }
179 /// tried to talk to an incompatible libt2n version
180 class t2n_version_mismatch : public t2n_communication_error
183 friend class boost::serialization::access;
184 template<class Archive>
185 void serialize(Archive & ar, const unsigned int version)
187 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_communication_error);
191 t2n_version_mismatch(const std::string& _message)
192 : t2n_communication_error(_message)
195 t2n_version_mismatch()
198 t2n_exception* clone() const
199 { return new t2n_version_mismatch(*this); }
205 /// illegal libt2n command received
206 class t2n_command_error : public t2n_exception
209 friend class boost::serialization::access;
210 template<class Archive>
211 void serialize(Archive & ar, const unsigned int version)
213 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
217 t2n_command_error(const std::string& _message)
218 : t2n_exception(_message)
224 t2n_exception* clone() const
225 { return new t2n_command_error(*this); }
231 /// error serializing or deserializing a libt2n command packet
232 class t2n_serialization_error : public t2n_exception
235 friend class boost::serialization::access;
236 template<class Archive>
237 void serialize(Archive & ar, const unsigned int version)
239 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
243 t2n_serialization_error(const std::string& _message)
244 : t2n_exception(_message)
247 t2n_serialization_error()
250 t2n_exception* clone() const
251 { return new t2n_serialization_error(*this); }
257 /** @brief a runtime error within the remote function.
258 derive your own custom exceptions from this one
260 class t2n_runtime_error : public t2n_exception
263 friend class boost::serialization::access;
264 template<class Archive>
265 void serialize(Archive & ar, const unsigned int version)
267 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t2n_exception);
271 t2n_runtime_error(const std::string& _message)
272 : t2n_exception(_message)
278 t2n_exception* clone() const
279 { return new t2n_runtime_error(*this); }
285 } // namespace libt2n