Repository navigation
Expand file tree
/
Copy pathsystem_error.cpp
More file actions
85 lines (74 loc) · 3.11 KB
/
Copy pathsystem_error.cpp
File metadata and controls
85 lines (74 loc) · 3.11 KB
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
#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include <cerrno>
#include <cstring>
using std::runtime_error;
using std::ostream;
class system_error : public runtime_error
{
class error_code
{
int errnum;
public:
explicit error_code(int errnum) : errnum(errnum) {}
operator int (void) const
{
return errnum;
}
friend ostream& operator << (ostream& stream, const error_code& error)
{
static char const * const macro[] = {
"SUCCESS",
"EPERM", "ENOENT", "ESRCH", "EINTR",
"EIO", "ENXIO", "E2BIG", "ENOEXEC",
"EBADF", "ECHILD", "EAGAIN", "ENOMEM",
"EACCES", "EFAULT", "ENOTBLK", "EBUSY",
"EEXIST", "EXDEV", "ENODEV", "ENOTDIR",
"EISDIR", "EINVAL", "ENFILE", "EMFILE",
"ENOTTY", "ETXTBSY", "EFBIG", "ENOSPC",
"ESPIPE", "EROFS", "EMLINK", "EPIPE",
"EDOM", "ERANGE", "EDEADLK", "ENAMETOOLONG",
"ENOLCK", "ENOSYS", "ENOTEMPTY", "ELOOP",
"?", "ENOMSG", "EIDRM", "ECHRNG",
"EL2NSYNC", "EL3HLT", "EL3RST", "ELNRNG",
"EUNATCH", "ENOCSI", "EL2HLT", "EBADE",
"EBADR", "EXFULL", "ENOANO", "EBADRQC",
"EBADSLT", "?", "EBFONT", "ENOSTR",
"ENODATA", "ETIME", "ENOSR", "ENONET",
"ENOPKG", "EREMOTE", "ENOLINK", "EADV",
"ESRMNT", "ECOMM", "EPROTO", "EMULTIHOP",
"EDOTDOT", "EBADMSG", "EOVERFLOW", "ENOTUNIQ",
"EBADFD", "EREMCHG", "ELIBACC", "ELIBBAD",
"ELIBSCN", "ELIBMAX", "ELIBEXEC", "EILSEQ",
"ERESTART", "ESTRPIPE", "EUSERS", "ENOTSOCK",
"EDESTADDRREQ", "EMSGSIZE", "EPROTOTYPE", "ENOPROTOOPT",
"EPROTONOSUPPORT", "ESOCKTNOSUPPORT", "EOPNOTSUPP", "EPFNOSUPPORT",
"EAFNOSUPPORT", "EADDRINUSE", "EADDRNOTAVAIL", "ENETDOWN",
"ENETUNREACH", "ENETRESET", "ECONNABORTED", "ECONNRESET",
"ENOBUFS", "EISCONN", "ENOTCONN", "ESHUTDOWN",
"ETOOMANYREFS", "ETIMEDOUT", "ECONNREFUSED", "EHOSTDOWN",
"EHOSTUNREACH", "EALREADY", "EINPROGRESS", "ESTALE",
"EUCLEAN", "ENOTNAM", "ENAVAIL", "EISNAM",
"EREMOTEIO", "EDQUOT", "ENOMEDIUM", "EMEDIUMTYPE",
"ECANCELED", "ENOKEY", "EKEYEXPIRED", "EKEYREVOKED",
"EKEYREJECTED", "EOWNERDEAD", "ENOTRECOVERABLE" };
return stream << macro[error.errnum];
}
} error;
public:
explicit system_error(int errnum) throw()
: runtime_error (::strerror(errnum)),
error (errnum)
{}
const error_code code() const
{
return error;
}
};
int main(int argc, const char *argv[])
{
class system_error e(5);
std::cout << e.code() << std::endl;
return EXIT_SUCCESS;
}