-
Notifications
You must be signed in to change notification settings - Fork 7
/
serverexceptions.h
106 lines (89 loc) · 2.78 KB
/
serverexceptions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <string>
#include <stdexcept>
#ifndef SERVEREXCEPTIONS_H
#define SERVEREXCEPTIONS_H
/**
* @file serverexceptions.h
* @brief File contains definitions of exceptions being thrown by ServerListener
*/
/**
* @brief Parent class for all exceptions being thrown by the ServerListener
*/
class ServerException : public std::runtime_error {
public:
/**
* @param info Information about the exception (possibly shown to the user)
*/
ServerException(std::string info) : std::runtime_error(info) {}
virtual ~ServerException() {}
};
/**
* @brief Exception being thrown in case of socket library initialization error
*/
class ServerStartupException : public ServerException {
public:
ServerStartupException()
: ServerException("Socket library initialization failed") {}
virtual ~ServerStartupException() {}
};
/**
* @brief Exception being thrown in case of addrinfo() returning an error code
*/
class AddrinfoException : public ServerException {
public:
AddrinfoException(int error_no)
: ServerException(
std::string("addrinfo() failed with error: ") +
std::to_string(error_no)
) {}
virtual ~AddrinfoException() {}
};
/**
* @brief Exception being thrown in case of socket() returning an error code
*/
class SocketCreationException : public ServerException {
public:
SocketCreationException(int error_no)
: ServerException(
std::string("socket() failed with error: ") +
std::to_string(error_no)
) {}
virtual ~SocketCreationException() {}
};
/**
* @brief Exception being thrown in case of bind() returning an error code
*/
class SocketBindingException : public ServerException {
public:
SocketBindingException(int error_no)
: ServerException(
std::string("bind() failed with error: ") +
std::to_string(error_no)
) {}
virtual ~SocketBindingException() {}
};
/**
* @brief Exception being thrown in case of listen() returning an error code
*/
class ListenException : public ServerException {
public:
ListenException(int error_no)
: ServerException(
std::string("listen() failed with error: ") +
std::to_string(error_no)
) {}
virtual ~ListenException() {}
};
/**
* @brief Exception being thrown in case of accept() returning an error code
*/
class ClientAcceptationException : public ServerException {
public:
ClientAcceptationException(int error_no)
: ServerException(
std::string("accept() failed with error: ") +
std::to_string(error_no)
) {}
virtual ~ClientAcceptationException() {}
};
#endif // SERVEREXCEPTIONS_H