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);
52 t2n_exception(const std::string& _message)
58 virtual const char* what() const throw()
59 { return message.c_str(); }
61 virtual t2n_exception* clone() const
62 { return new t2n_exception(*this); }
64 virtual ~t2n_exception() throw()
67 virtual void do_throw()
71 /// a (unspecified) problem with libt2n communication
72 class t2n_communication_error : public t2n_exception
75 friend class boost::serialization::access;
76 template<class Archive>
77 void serialize(Archive & ar, const unsigned int version);
80 t2n_communication_error(const std::string& _message)
81 : t2n_exception(_message)
84 t2n_communication_error()
87 t2n_exception* clone() const
88 { return new t2n_communication_error(*this); }
94 /// can't connect to libt2n server
95 class t2n_connect_error : public t2n_communication_error
98 friend class boost::serialization::access;
99 template<class Archive>
100 void serialize(Archive & ar, const unsigned int version);
103 t2n_connect_error(const std::string& _message)
104 : t2n_communication_error(_message)
110 t2n_exception* clone() const
111 { return new t2n_connect_error(*this); }
117 /// error establishing a socket on the server (only thrown on the server-side)
118 class t2n_server_error : public t2n_communication_error
121 friend class boost::serialization::access;
122 template<class Archive>
123 void serialize(Archive & ar, const unsigned int version);
126 t2n_server_error(const std::string& _message)
127 : t2n_communication_error(_message)
133 t2n_exception* clone() const
134 { return new t2n_server_error(*this); }
140 /// error transmitting or receiving libt2n messages
141 class t2n_transfer_error : public t2n_communication_error
144 friend class boost::serialization::access;
145 template<class Archive>
146 void serialize(Archive & ar, const unsigned int version);
149 t2n_transfer_error(const std::string& _message)
150 : t2n_communication_error(_message)
156 t2n_exception* clone() const
157 { return new t2n_transfer_error(*this); }
163 /// tried to talk to an incompatible libt2n version
164 class t2n_version_mismatch : public t2n_communication_error
167 friend class boost::serialization::access;
168 template<class Archive>
169 void serialize(Archive & ar, const unsigned int version);
172 t2n_version_mismatch(const std::string& _message)
173 : t2n_communication_error(_message)
176 t2n_version_mismatch()
179 t2n_exception* clone() const
180 { return new t2n_version_mismatch(*this); }
186 /// illegal libt2n command received
187 class t2n_command_error : public t2n_exception
190 friend class boost::serialization::access;
191 template<class Archive>
192 void serialize(Archive & ar, const unsigned int version);
195 t2n_command_error(const std::string& _message)
196 : t2n_exception(_message)
202 t2n_exception* clone() const
203 { return new t2n_command_error(*this); }
209 /// error serializing or deserializing a libt2n command packet
210 class t2n_serialization_error : public t2n_exception
213 friend class boost::serialization::access;
214 template<class Archive>
215 void serialize(Archive & ar, const unsigned int version);
218 t2n_serialization_error(const std::string& _message)
219 : t2n_exception(_message)
222 t2n_serialization_error()
225 t2n_exception* clone() const
226 { return new t2n_serialization_error(*this); }
232 /** @brief a runtime error within the remote function.
233 derive your own custom exceptions from this one
235 class t2n_runtime_error : public t2n_exception
238 friend class boost::serialization::access;
239 template<class Archive>
240 void serialize(Archive & ar, const unsigned int version);
243 t2n_runtime_error(const std::string& _message)
244 : t2n_exception(_message)
250 t2n_exception* clone() const
251 { return new t2n_runtime_error(*this); }
257 } // namespace libt2n