-
Notifications
You must be signed in to change notification settings - Fork 0
/
Error.hpp
84 lines (61 loc) · 2.19 KB
/
Error.hpp
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
#pragma once
#include <typeinfo>
// Base class for error reporting
struct GeneralError;
class GeneralErrorHandler {
public:
// Error codes
enum GenErrCode {
OK = 0,
Unknown, // for debug
// Fatal system errors
NoCommCtl, ScrnRes, GDI, System, OutOfMem,
// Non-fatal system errors
FileOpen, FileClose, FileWrite, NoRichEdit, NoHelpFile,
// Non-fatal application errors
AppWrongFileFormat,
AppNotEnoughVertices,
AppOutOfRangeFile,
AppOutOfRangeW,
AppOutOfRangeR
};
protected:
explicit GeneralErrorHandler(GenErrCode, GeneralError* = nullptr);
GeneralErrorHandler() = delete;
virtual ~GeneralErrorHandler() = default;
// On error, throw an exception (mostly for fatal errors)
virtual void Throw(unsigned where) const; // with default error code
virtual void Throw(unsigned where, GenErrCode what) const;
virtual void Throw(GeneralError gen_err) const;
// On error, post info about it to an external pointer
virtual void Post(unsigned where) const; // with default error code
virtual void Post(unsigned where, GenErrCode what) const;
// On error, do something defined in a derived class
// By default - do nothing
virtual void OnError(unsigned where); // with default error code
virtual void OnError(unsigned where, GenErrCode what);
// Deduce the type name where the error happened
virtual const char* my_name() const;
// Default error code
const GenErrCode default_err_code;
// External pointer for Post, can be nullptr in which case - no posting
GeneralError* const external_err_ptr;
};
struct GeneralError {
const unsigned where;
const GeneralErrorHandler::GenErrCode what;
const char* class_name;
GeneralError() = delete;
GeneralError(
unsigned where,
GeneralErrorHandler::GenErrCode what,
const char* class_name)
: where(where), what(what), class_name(class_name) {}
};
inline GeneralErrorHandler::GeneralErrorHandler(
GenErrCode default_err_code, GeneralError* external_err_ptr)
: external_err_ptr{ external_err_ptr }, default_err_code{ default_err_code }
{
if (external_err_ptr != nullptr)
external_err_ptr->GeneralError::GeneralError(0, OK, nullptr);
}