00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef SOCKETEXCEPTION_HH_
00024 # define SOCKETEXCEPTION_HH_
00025
00026 #define HERE __FILE__, __LINE__
00027
00028 #include <iostream>
00029 #include <string>
00030
00031 #define NEW_EXCEPTION(Name) \
00032 class Name : public Exception \
00033 { \
00034 public: \
00035 Name(const std::string& desc, const char * file, int line) : \
00036 Exception(desc, file, line) \
00037 {} \
00038 Name() : Exception() {} \
00039 Name(const char *file, int line) : Exception(file, line) {} \
00040 };
00041
00042 namespace Network
00043 {
00044
00047 class Exception
00048 {
00049 public:
00050 Exception() :
00051 _error("Exception Occured"), _file(0x0), _line(0)
00052 {}
00053
00054 Exception(const char *file, int line) :
00055 _error("Exception Occured"), _file(file), _line(line)
00056 {}
00057
00058 Exception(const std::string& err, const char* file, int line) :
00059 _file(file), _line(line)
00060 {
00061 _error = "Exception: " + err;
00062 }
00063
00064 void print(std::ostream& stream) const;
00065 const std::string& get_error() const;
00066 const char* get_file() const;
00067 int get_line() const;
00068
00069 protected:
00070 std::string _error;
00071 const char* _file;
00072 int _line;
00073 };
00074
00075 std::ostream& operator<<(std::ostream& stream, Exception& e);
00076
00078 NEW_EXCEPTION(HostnameError);
00081 NEW_EXCEPTION(Ipv6SupportError);
00084 NEW_EXCEPTION(TLSError);
00086 NEW_EXCEPTION(InvalidFile);
00089 NEW_EXCEPTION(TLSSupportError);
00091 NEW_EXCEPTION(InetptonError);
00093 NEW_EXCEPTION(InetntopError);
00095 NEW_EXCEPTION(ConnectionClosed);
00097 NEW_EXCEPTION(NoConnection);
00099 NEW_EXCEPTION(Timeout);
00101 NEW_EXCEPTION(BindError);
00103 NEW_EXCEPTION(SocketError);
00105 NEW_EXCEPTION(ListenError);
00107 NEW_EXCEPTION(SetsockoptError);
00109 NEW_EXCEPTION(CloseError);
00111 NEW_EXCEPTION(SelectError);
00113 NEW_EXCEPTION(ConnectError);
00115 NEW_EXCEPTION(AcceptError);
00117 NEW_EXCEPTION(GetpeernameError);
00120 NEW_EXCEPTION(WSAStartupError);
00121
00122 }
00123
00124 #endif