-
Notifications
You must be signed in to change notification settings - Fork 16
/
ErrHandling.h
53 lines (50 loc) · 1.65 KB
/
ErrHandling.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
// -*- c++ -*-
#ifndef __INCLUDE_ERRHANDLING_H__
#define __INCLUDE_ERRHANDLING_H__
#include <string>
#include <cerrno>
#include <cstring>
class ErrHandling {
public:
class ErrBase: public std::exception {
protected:
const std::string func;
const std::string msg;
std::string huh;
public:
ErrBase(const std::string &func,
const std::string &msg)
:func(func),msg(msg)
{
huh = func + ": " + msg;
}
virtual ~ErrBase() throw() {}
const char *what() const throw() { return huh.c_str(); };
const char *whatMsg() const throw() { return msg.c_str(); };
};
class ErrMalformed: public ErrBase {
public:
ErrMalformed(const std::string &func,
const std::string &msg)
:ErrBase(func, msg) { }
};
class ErrSys: public ErrBase {
protected:
const std::string sys;
int err;
public:
ErrSys(const std::string &func,
const std::string &sys,
const std::string &msg = "")
:ErrBase(func, msg),sys(sys)
{
err = errno;
huh = func + ": "
+ sys + "(): "
+ strerror(errno) + ": "
+ msg;
}
virtual ~ErrSys() throw() {}
};
};
#endif