/*************************************************************************** * Copyright (C) 2006 by Gerd v. Egidy * * gve@intra2net.com * * * * This library is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef __LIBT2N_T2N_EXCEPTION #define __LIBT2N_T2N_EXCEPTION #include #include #include namespace boost { namespace serialization { // make std::exception serializable template void serialize(Archive & ar, std::exception & g, const unsigned int version) { } } // namespace serialization } // namespace boost namespace libt2n { /// a generic exception that can be handeled with libt2n class t2n_exception : public std::exception { private: std::string message; friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned int version); public: t2n_exception(const std::string& _message) { message=_message; } t2n_exception() { } virtual const char* what() const throw() { return message.c_str(); } virtual t2n_exception* clone() const { return new t2n_exception(*this); } virtual ~t2n_exception() throw() {} virtual void do_throw() { throw *this; } }; /// a (unspecified) problem with libt2n communication class t2n_communication_error : public t2n_exception { private: friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned int version); public: t2n_communication_error(const std::string& _message) : t2n_exception(_message) { } t2n_communication_error() { } t2n_exception* clone() const { return new t2n_communication_error(*this); } void do_throw() { throw *this; } }; /// can't connect to libt2n server class t2n_connect_error : public t2n_communication_error { private: friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned int version); public: t2n_connect_error(const std::string& _message) : t2n_communication_error(_message) { } t2n_connect_error() { } t2n_exception* clone() const { return new t2n_connect_error(*this); } void do_throw() { throw *this; } }; /// error establishing a socket on the server (only thrown on the server-side) class t2n_server_error : public t2n_communication_error { private: friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned int version); public: t2n_server_error(const std::string& _message) : t2n_communication_error(_message) { } t2n_server_error() { } t2n_exception* clone() const { return new t2n_server_error(*this); } void do_throw() { throw *this; } }; /// error transmitting or receiving libt2n messages class t2n_transfer_error : public t2n_communication_error { private: friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned int version); public: t2n_transfer_error(const std::string& _message) : t2n_communication_error(_message) { } t2n_transfer_error() { } t2n_exception* clone() const { return new t2n_transfer_error(*this); } void do_throw() { throw *this; } }; /// tried to talk to an incompatible libt2n version class t2n_version_mismatch : public t2n_communication_error { private: friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned int version); public: t2n_version_mismatch(const std::string& _message) : t2n_communication_error(_message) { } t2n_version_mismatch() { } t2n_exception* clone() const { return new t2n_version_mismatch(*this); } void do_throw() { throw *this; } }; /// illegal libt2n command received class t2n_command_error : public t2n_exception { private: friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned int version); public: t2n_command_error(const std::string& _message) : t2n_exception(_message) { } t2n_command_error() { } t2n_exception* clone() const { return new t2n_command_error(*this); } void do_throw() { throw *this; } }; /// error serializing or deserializing a libt2n command packet class t2n_serialization_error : public t2n_exception { private: friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned int version); public: t2n_serialization_error(const std::string& _message) : t2n_exception(_message) { } t2n_serialization_error() { } t2n_exception* clone() const { return new t2n_serialization_error(*this); } void do_throw() { throw *this; } }; /** @brief a runtime error within the remote function. derive your own custom exceptions from this one */ class t2n_runtime_error : public t2n_exception { private: friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned int version); public: t2n_runtime_error(const std::string& _message) : t2n_exception(_message) { } t2n_runtime_error() { } t2n_exception* clone() const { return new t2n_runtime_error(*this); } void do_throw() { throw *this; } }; } // namespace libt2n #endif