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 /** @brief a generic exception that can be handeled with libt2n
42 @note don't derive the exceptions your application generates directly from this one
43 but use libt2n::t2n_runtime_error for this
45 class t2n_exception : public std::exception
50 friend class boost::serialization::access;
51 template<class Archive>
52 void serialize(Archive & ar, const unsigned int version);
55 t2n_exception(const std::string& _message)
61 virtual const char* what() const throw()
62 { return message.c_str(); }
64 virtual t2n_exception* clone() const
65 { return new t2n_exception(*this); }
67 virtual ~t2n_exception() throw()
70 virtual void do_throw()
74 /// a (unspecified) problem with libt2n communication
75 class t2n_communication_error : public t2n_exception
78 friend class boost::serialization::access;
79 template<class Archive>
80 void serialize(Archive & ar, const unsigned int version);
83 t2n_communication_error(const std::string& _message)
84 : t2n_exception(_message)
87 t2n_communication_error()
90 t2n_exception* clone() const
91 { return new t2n_communication_error(*this); }
97 /// can't connect to libt2n server
98 class t2n_connect_error : public t2n_communication_error
101 friend class boost::serialization::access;
102 template<class Archive>
103 void serialize(Archive & ar, const unsigned int version);
106 t2n_connect_error(const std::string& _message)
107 : t2n_communication_error(_message)
113 t2n_exception* clone() const
114 { return new t2n_connect_error(*this); }
120 /// error establishing a socket on the server (only thrown on the server-side)
121 class t2n_server_error : public t2n_communication_error
124 friend class boost::serialization::access;
125 template<class Archive>
126 void serialize(Archive & ar, const unsigned int version);
129 t2n_server_error(const std::string& _message)
130 : t2n_communication_error(_message)
136 t2n_exception* clone() const
137 { return new t2n_server_error(*this); }
143 /// error transmitting or receiving libt2n messages
144 class t2n_transfer_error : public t2n_communication_error
147 friend class boost::serialization::access;
148 template<class Archive>
149 void serialize(Archive & ar, const unsigned int version);
152 t2n_transfer_error(const std::string& _message)
153 : t2n_communication_error(_message)
159 t2n_exception* clone() const
160 { return new t2n_transfer_error(*this); }
166 /// tried to talk to an incompatible libt2n version
167 class t2n_version_mismatch : public t2n_communication_error
170 friend class boost::serialization::access;
171 template<class Archive>
172 void serialize(Archive & ar, const unsigned int version);
175 t2n_version_mismatch(const std::string& _message)
176 : t2n_communication_error(_message)
179 t2n_version_mismatch()
182 t2n_exception* clone() const
183 { return new t2n_version_mismatch(*this); }
189 /// illegal libt2n command received
190 class t2n_command_error : public t2n_exception
193 friend class boost::serialization::access;
194 template<class Archive>
195 void serialize(Archive & ar, const unsigned int version);
198 t2n_command_error(const std::string& _message)
199 : t2n_exception(_message)
205 t2n_exception* clone() const
206 { return new t2n_command_error(*this); }
212 /// error serializing or deserializing a libt2n command packet
213 class t2n_serialization_error : public t2n_exception
216 friend class boost::serialization::access;
217 template<class Archive>
218 void serialize(Archive & ar, const unsigned int version);
221 t2n_serialization_error(const std::string& _message)
222 : t2n_exception(_message)
225 t2n_serialization_error()
228 t2n_exception* clone() const
229 { return new t2n_serialization_error(*this); }
235 /** @brief a runtime error within the remote function.
236 derive your own custom exceptions from this one
238 @note you must override the virtual clone method if you do so (used by libt2n::command_server::handle())
240 class t2n_runtime_error : public t2n_exception
243 friend class boost::serialization::access;
244 template<class Archive>
245 void serialize(Archive & ar, const unsigned int version);
248 t2n_runtime_error(const std::string& _message)
249 : t2n_exception(_message)
255 t2n_exception* clone() const
256 { return new t2n_runtime_error(*this); }
262 } // namespace libt2n