libsocket 1.5
|
00001 /* 00002 ** socketexception.hh 00003 ** Login : Julien Lemoine <speedblue@happycoders.org> 00004 ** Started on Mon May 12 22:50:50 2003 Julien Lemoine 00005 ** $Id: socketexception.hh,v 1.6 2004/06/06 14:13:56 speedblue Exp $ 00006 ** 00007 ** Copyright (C) 2003,2004 Julien Lemoine 00008 ** This program is free software; you can redistribute it and/or modify 00009 ** it under the terms of the GNU Lesser General Public License as published by 00010 ** the Free Software Foundation; either version 2 of the License, or 00011 ** (at your option) any later version. 00012 ** 00013 ** This program is distributed in the hope that it will be useful, 00014 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 ** GNU Lesser General Public License for more details. 00017 ** 00018 ** You should have received a copy of the GNU Lesser General Public License 00019 ** along with this program; if not, write to the Free Software 00020 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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 /* !SOCKETEXCEPTION_HH_ */