Repository navigation
Expand file tree
/
Copy pathunix_error.cc
More file actions
55 lines (45 loc) · 1.48 KB
/
Copy pathunix_error.cc
File metadata and controls
55 lines (45 loc) · 1.48 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
/** @file unix_error.cc
* The implementation of the unix_error exception class.
* @version 4.1 2015/01/24
*/
// linux & c++ hooks
#include <cstring> // extern char *strerror(int errnum);
#include <cerrno> // extern int errno;
#include <sstream> // ostringstream
// our own stuff
#include "unix_error.h" // class unix_error
static // (i.e. only visible in this source file)
// A function to combine the given argument with the unix error message
// that belongs with the given errornumber into a nice c++ string.
std::string makeErrorString(const std::string& what, int errornumber)
{
std::ostringstream s;
if (!what.empty()) {
s << what << ": ";
} else {
s << "errno=" << errornumber << ": ";
}
s << strerror(errornumber);
return s.str();
}
// Construct a unix system error
unix_error::unix_error(const std::string& what)
: std::runtime_error( makeErrorString(what, errno) ), uxerror(errno)
{
}
// Construct a unix system error
unix_error::unix_error(const char *what)
: std::runtime_error( makeErrorString( std::string(what), errno) ), uxerror(errno)
{
}
// Construct a unix system error
unix_error::unix_error(const std::string& where, const char *what)
: std::runtime_error( where + "\n\t" + makeErrorString( std::string(what), errno) ), uxerror(errno)
{
}
// Construct a unix system error
unix_error::unix_error(const std::string& where, const std::string& what)
: std::runtime_error( where + "\n\t" + makeErrorString( what, errno) ), uxerror(errno)
{
}
// vim:sw=4:ai:aw:ts=4: