2 Copyright (C) 2006 by Intra2net AG - Gerd v. Egidy
4 The software in this package is distributed under the GNU General
5 Public License version 2 (with a special exception described below).
7 A copy of GNU General Public License (GPL) is included in this distribution,
8 in the file COPYING.GPL.
10 As a special exception, if other files instantiate templates or use macros
11 or inline functions from this file, or you compile this file and link it
12 with other works to produce a work based on this file, this file
13 does not by itself cause the resulting work to be covered
14 by the GNU General Public License.
16 However the source code for this file must still be made available
17 in accordance with section (3) of the GNU General Public License.
19 This exception does not invalidate any other reasons why a work based
20 on this file might be covered by the GNU General Public License.
22 #ifndef __LIBT2N_T2N_EXCEPTION
23 #define __LIBT2N_T2N_EXCEPTION
28 #include <boost/serialization/serialization.hpp>
31 namespace serialization {
33 // make std::exception serializable
34 template<class Archive>
35 void serialize(Archive & ar, std::exception & g, const unsigned int version)
39 } // namespace serialization
44 /** @brief a generic exception that can be handeled with libt2n
45 @note don't derive the exceptions your application generates directly from this one
46 but use libt2n::t2n_runtime_error for this
48 class t2n_exception : public std::exception
53 friend class boost::serialization::access;
54 template<class Archive>
55 void serialize(Archive & ar, const unsigned int version);
58 t2n_exception(const std::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()
77 /// a (unspecified) problem with libt2n communication
78 class t2n_communication_error : public t2n_exception
81 friend class boost::serialization::access;
82 template<class Archive>
83 void serialize(Archive & ar, const unsigned int version);
86 t2n_communication_error(const std::string& _message)
87 : t2n_exception(_message)
90 t2n_communication_error()
93 t2n_exception* clone() const
94 { return new t2n_communication_error(*this); }
100 /// can't connect to libt2n server
101 class t2n_connect_error : public t2n_communication_error
104 friend class boost::serialization::access;
105 template<class Archive>
106 void serialize(Archive & ar, const unsigned int version);
109 t2n_connect_error(const std::string& _message)
110 : t2n_communication_error(_message)
116 t2n_exception* clone() const
117 { return new t2n_connect_error(*this); }
123 /// error establishing a socket on the server (only thrown on the server-side)
124 class t2n_server_error : public t2n_communication_error
127 friend class boost::serialization::access;
128 template<class Archive>
129 void serialize(Archive & ar, const unsigned int version);
132 t2n_server_error(const std::string& _message)
133 : t2n_communication_error(_message)
139 t2n_exception* clone() const
140 { return new t2n_server_error(*this); }
146 /// error transmitting or receiving libt2n messages
147 class t2n_transfer_error : public t2n_communication_error
150 friend class boost::serialization::access;
151 template<class Archive>
152 void serialize(Archive & ar, const unsigned int version);
155 t2n_transfer_error(const std::string& _message)
156 : t2n_communication_error(_message)
162 t2n_exception* clone() const
163 { return new t2n_transfer_error(*this); }
169 /// tried to talk to an incompatible libt2n version
170 class t2n_version_mismatch : public t2n_communication_error
173 friend class boost::serialization::access;
174 template<class Archive>
175 void serialize(Archive & ar, const unsigned int version);
178 t2n_version_mismatch(const std::string& _message)
179 : t2n_communication_error(_message)
182 t2n_version_mismatch()
185 t2n_exception* clone() const
186 { return new t2n_version_mismatch(*this); }
192 /// illegal libt2n command received
193 class t2n_command_error : public t2n_exception
196 friend class boost::serialization::access;
197 template<class Archive>
198 void serialize(Archive & ar, const unsigned int version);
201 t2n_command_error(const std::string& _message)
202 : t2n_exception(_message)
208 t2n_exception* clone() const
209 { return new t2n_command_error(*this); }
215 /// error serializing or deserializing a libt2n command packet
216 class t2n_serialization_error : public t2n_exception
219 friend class boost::serialization::access;
220 template<class Archive>
221 void serialize(Archive & ar, const unsigned int version);
224 t2n_serialization_error(const std::string& _message)
225 : t2n_exception(_message)
228 t2n_serialization_error()
231 t2n_exception* clone() const
232 { return new t2n_serialization_error(*this); }
238 /** @brief a runtime error within the remote function.
239 derive your own custom exceptions from this one
241 @note you must override the virtual clone method if you do so (used by libt2n::command_server::handle())
243 class t2n_runtime_error : public t2n_exception
246 friend class boost::serialization::access;
247 template<class Archive>
248 void serialize(Archive & ar, const unsigned int version);
251 t2n_runtime_error(const std::string& _message)
252 : t2n_exception(_message)
258 t2n_exception* clone() const
259 { return new t2n_runtime_error(*this); }
265 } // namespace libt2n
267 #include "t2n_exception.tcc"