00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef CONEXUSEXCEPT_H
00020 #define CONEXUSEXCEPT_H
00021
00026 #include <stdexcept>
00027 #include <errno.h>
00028 #include <sstream>
00029
00030 namespace Conexus
00031 {
00032
00038 class conexus_exception: public std::runtime_error
00039 {
00040 public:
00041 conexus_exception(const std::string s="Unknown exception.", int e=0, const std::string c=""):
00042 std::runtime_error(s),
00043 m_exception_number(e),
00044 m_exception_string(s),
00045 m_class(c)
00046 {
00047 if (m_exception_number == 0)
00048 m_exception_number = errno;
00049 std::ostringstream ostr;
00050 ostr << "conexus:" << m_class << ":";
00051 if (m_exception_number != 0)
00052 ostr << "errno[" << m_exception_number << "]: ";
00053 else
00054 ostr << " ";
00055 ostr << m_exception_string;
00056 m_return_string = ostr.str();
00057 }
00058
00059 ~conexus_exception() throw () { }
00060
00061 virtual const char * what () const throw () {
00062 return m_return_string.c_str();
00063 }
00064
00065 protected:
00066 int m_exception_number;
00067 std::string m_return_string;
00068 std::string m_exception_string;
00069 std::string m_class;
00070 }
00071 ;
00072
00073 }
00074
00075 #include <conexus/except_address.h>
00076 #include <conexus/except_bind.h>
00077 #include <conexus/except_close.h>
00078 #include <conexus/except_connect.h>
00079 #include <conexus/except_listen.h>
00080 #include <conexus/except_open.h>
00081 #include <conexus/except_read.h>
00082 #include <conexus/except_state.h>
00083 #include <conexus/except_write.h>
00084
00085 namespace Conexus {
00086
00087 typedef enum ExceptionType {
00088 EXCEPTION_OPEN,
00089 EXCEPTION_BIND,
00090 EXCEPTION_CLOSE,
00091 EXCEPTION_CONNECT,
00092 EXCEPTION_LISTEN,
00093 EXCEPTION_READ,
00094 EXCEPTION_STATE,
00095 EXCEPTION_WRITE,
00096 EXCEPTION_ADDRESS,
00097 } ExceptionType;
00098
00099 void throw_exception(int exception_num, ExceptionType type) throw (conexus_exception);
00100
00101 void throw_bind_exception(int exception_num) throw (bind_exception);
00102 void throw_close_exception(int exception_num) throw (close_exception);
00103 void throw_connect_exception(int exception_num) throw (connect_exception);
00104 void throw_listen_exception(int exception_num) throw (listen_exception);
00105 void throw_open_exception(int exception_num) throw (open_exception);
00106 void throw_read_exception(int exception_num) throw (read_exception);
00107 void throw_write_exception(int exception_num) throw (write_exception);
00108 void throw_address_exception(int exception_num) throw (address_exception);
00109
00110 }
00111
00112 #endif
00113