forked from pt209223/librs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Exception.h
69 lines (60 loc) · 2.33 KB
/
Exception.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
/**
* @brief Hierarchia wyjatkow
* @author Piotr Truszkowski
*/
#ifndef __EXCEPTION_H__
#define __EXCEPTION_H__
#include <exception>
#include <cstdlib>
#include <cstdio>
#include <cerrno>
#include <cstring>
#include <stdarg.h>
// @brief: glowny wyjatek, po nim dziedzicza inne
class Exception : public std::exception {
public:
Exception(void) throw() { }
const char *what(void) const throw() { return "Exception"; }
};
// @brief: szablon dla wyjatkow prostych
#define DEF_EXC(name, up) \
class name : public up { \
public: \
name(void) throw() { } \
\
const char *what(void) const throw() \
{ \
return #name; \
} \
}
// @brief: szablon dla wyjatkow z opisem
#define DEF_EXC_WITH_DESCR(name, up) \
class name : public up { \
public: \
name(void) throw() \
{ \
snprintf(exc, maxexclen, #name); \
} \
\
name(const char *fmt, ...) throw() \
{ \
va_list args; \
va_start(args, fmt); \
vsnprintf(exc, maxexclen, fmt, args); \
va_end(args); \
} \
\
const char *what(void) const throw() \
{ \
return exc; \
} \
\
private: \
static const size_t maxexclen = 256; \
char exc[maxexclen]; \
}
// @brief: blad wewnetrzny, aplikacji lub blad w programie
DEF_EXC_WITH_DESCR(EInternal, Exception);
// @brief: blad zewnetrzy, bledne argumenty, itp...
DEF_EXC_WITH_DESCR(EExternal, Exception);
#endif