libsocket 1.5
socketexception.hh
Go to the documentation of this file.
1/*
2** socketexception.hh
3** Login : Julien Lemoine <speedblue@happycoders.org>
4** Started on Mon May 12 22:50:50 2003 Julien Lemoine
5** $Id: socketexception.hh,v 1.6 2004/06/06 14:13:56 speedblue Exp $
6**
7** Copyright (C) 2003,2004 Julien Lemoine
8** This program is free software; you can redistribute it and/or modify
9** it under the terms of the GNU Lesser General Public License as published by
10** the Free Software Foundation; either version 2 of the License, or
11** (at your option) any later version.
12**
13** This program is distributed in the hope that it will be useful,
14** but WITHOUT ANY WARRANTY; without even the implied warranty of
15** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16** GNU Lesser General Public License for more details.
17**
18** You should have received a copy of the GNU Lesser General Public License
19** along with this program; if not, write to the Free Software
20** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21*/
22
23#ifndef SOCKETEXCEPTION_HH_
24# define SOCKETEXCEPTION_HH_
25
26#define HERE __FILE__, __LINE__
27
28#include <iostream>
29#include <string>
30
31#define NEW_EXCEPTION(Name) \
32 class Name : public Exception \
33 { \
34 public: \
35 Name(const std::string& desc, const char * file, int line) : \
36 Exception(desc, file, line) \
37 {} \
38 Name() : Exception() {} \
39 Name(const char *file, int line) : Exception(file, line) {} \
40 };
41
42namespace Network
43{
44
48 {
49 public:
51 _error("Exception Occured"), _file(0x0), _line(0)
52 {}
53
54 Exception(const char *file, int line) :
55 _error("Exception Occured"), _file(file), _line(line)
56 {}
57
58 Exception(const std::string& err, const char* file, int line) :
59 _file(file), _line(line)
60 {
61 _error = "Exception: " + err;
62 }
63
64 void print(std::ostream& stream) const;
65 const std::string& get_error() const;
66 const char* get_file() const;
67 int get_line() const;
68
69 protected:
70 std::string _error;
71 const char* _file;
72 int _line;
73 };
74
75 std::ostream& operator<<(std::ostream& stream, Exception& e);
76
78 NEW_EXCEPTION(HostnameError);
81 NEW_EXCEPTION(Ipv6SupportError);
84 NEW_EXCEPTION(TLSError);
86 NEW_EXCEPTION(InvalidFile);
89 NEW_EXCEPTION(TLSSupportError);
91 NEW_EXCEPTION(InetptonError);
93 NEW_EXCEPTION(InetntopError);
95 NEW_EXCEPTION(ConnectionClosed);
97 NEW_EXCEPTION(NoConnection);
99 NEW_EXCEPTION(Timeout);
101 NEW_EXCEPTION(BindError);
103 NEW_EXCEPTION(SocketError);
105 NEW_EXCEPTION(ListenError);
107 NEW_EXCEPTION(SetsockoptError);
109 NEW_EXCEPTION(CloseError);
111 NEW_EXCEPTION(SelectError);
113 NEW_EXCEPTION(ConnectError);
115 NEW_EXCEPTION(AcceptError);
117 NEW_EXCEPTION(GetpeernameError);
120 NEW_EXCEPTION(WSAStartupError);
121
122}
123
124#endif /* !SOCKETEXCEPTION_HH_ */
This class is the top exception class used in libsocket.
const std::string & get_error() const
void print(std::ostream &stream) const
const char * get_file() const
Exception(const std::string &err, const char *file, int line)
Exception(const char *file, int line)
Network namespace represent all networks connection.
Definition: localsocket.cc:33
Socket & operator<<(Socket &s, const std::string &str)
write a string on current socket
Definition: socket.cc:367
NEW_EXCEPTION(HostnameError)
exception launched when a hostname is incorrect