00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef CONEXUSERROR_H
00020 #define CONEXUSERROR_H
00021
00026 #include <stdexcept>
00027 #include <errno.h>
00028 #include <sstream>
00029
00030 namespace Conexus
00031 {
00032
00038 class conexus_error: public std::runtime_error
00039 {
00040 public:
00041 conexus_error(const std::string s="Unknown error.", int e=0, const std::string c=""):
00042 std::runtime_error(s),
00043 m_error_number(e),
00044 m_error_string(s),
00045 m_class(c)
00046 {
00047 if (m_error_number == 0)
00048 m_error_number = errno;
00049 std::ostringstream ostr;
00050 ostr << "conexus:" << m_class << ":";
00051 if (m_error_number != 0)
00052 ostr << "errno[" << m_error_number << "]: ";
00053 else
00054 ostr << " ";
00055 ostr << m_error_string;
00056 m_return_string = ostr.str();
00057 }
00058
00059 ~conexus_error() throw () { }
00060
00061 virtual const char * what () const throw () {
00062 return m_return_string.c_str();
00063 }
00064
00065 protected:
00066 int m_error_number;
00067 std::string m_return_string;
00068 std::string m_error_string;
00069 std::string m_class;
00070 }
00071 ;
00072
00073 }
00074
00075 #include <conexus/error_address.h>
00076 #include <conexus/error_bind.h>
00077 #include <conexus/error_close.h>
00078 #include <conexus/error_connect.h>
00079 #include <conexus/error_listen.h>
00080 #include <conexus/error_open.h>
00081 #include <conexus/error_read.h>
00082 #include <conexus/error_state.h>
00083 #include <conexus/error_write.h>
00084
00085 namespace Conexus {
00086
00087 typedef enum ErrorType {
00088 ERROR_OPEN,
00089 ERROR_BIND,
00090 ERROR_CLOSE,
00091 ERROR_CONNECT,
00092 ERROR_LISTEN,
00093 ERROR_READ,
00094 ERROR_STATE,
00095 ERROR_WRITE,
00096 ERROR_ADDRESS,
00097 } ErrorType;
00098
00099 void throw_error(int error_num, ErrorType type) throw (conexus_error);
00100
00101 void throw_bind_error(int error_num) throw (bind_error);
00102 void throw_close_error(int error_num) throw (close_error);
00103 void throw_connect_error(int error_num) throw (connect_error);
00104 void throw_listen_error(int error_num) throw (listen_error);
00105 void throw_open_error(int error_num) throw (open_error);
00106 void throw_read_error(int error_num) throw (read_error);
00107 void throw_write_error(int error_num) throw (write_error);
00108 void throw_address_error(int error_num) throw (address_error);
00109
00110 }
00111
00112 #endif
00113