-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarty_cpp_exceptions.h
155 lines (105 loc) · 4.23 KB
/
marty_cpp_exceptions.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#pragma once
#include <exception>
#include <stdexcept>
#include <string>
// failed to deserialize value
namespace marty_cpp {
// Тут нужно int except_id_
// int except_id_base_error = 1;
// int except_id_file_not_exist_or_empty = 1;
class base_error : public std::runtime_error // exception
{
typedef std::runtime_error base_exception_t;
public:
/*
/// returns the explanatory string
const char* what() const noexcept override
{
return m.what();
}
*/
const int id ;
const std::string name;
const std::string mtrCategory = "marty_cpp";
base_error(const std::string& what_arg, int id_ = 0, const std::string &mtrc="marty_cpp") : base_exception_t(what_arg ), id(id_), name("marty_cpp::base_error"), mtrCategory(mtrc) {}
base_error(const char* what_arg , int id_ = 0, const std::string &mtrc="marty_cpp") : base_exception_t(std::string(what_arg)), id(id_), name("marty_cpp::base_error"), mtrCategory(mtrc) {}
base_error( const char *errName, const char *errMsg, int id_ = 0, const std::string &mtrc="marty_cpp")
: base_exception_t(std::string("[") + std::string(errName) + std::string("]: ") + std::string(errMsg))
, id(id_)
, name(std::string(errName))
, mtrCategory(mtrc)
{}
base_error( const char *errName, const std::string &errMsg, int id_ = 0, const std::string &mtrc="marty_cpp")
: base_exception_t(std::string("[") + std::string(errName) + std::string("]: ") + errMsg)
, id(id_)
, name(std::string(errName))
, mtrCategory(mtrc)
{}
base_error(const base_error &e)
: base_exception_t(e)
, id(e.id)
, name(e.name)
, mtrCategory(e.mtrCategory)
{}
base_error& operator=(const base_error& e) = delete;
}; // class base_error
class file_not_exist_or_empty : public base_error
{
public:
const std::string fileName;
file_not_exist_or_empty(const std::string &fileName_, int id_ = 0, const std::string &mtrc="marty_cpp")
: base_error( "File not exist or empty" // "marty_cpp::file_not_exist_or_empty"
, fileName_
, id_
, mtrc
)
, fileName(fileName_)
{}
file_not_exist_or_empty(const file_not_exist_or_empty &e)
: base_error(e)
, fileName(e.fileName)
{}
file_not_exist_or_empty& operator=(const file_not_exist_or_empty& e) = delete;
};
class generic_serialization_error : public base_error
{
public:
const std::string typeName;
const std::string value ;
generic_serialization_error( const char *errName, const char *errMsg, const char *typeName_, const std::string &val, int id_ = 0, const std::string &mtrc="marty_cpp" )
: base_error( errName
, std::string(errMsg) + std::string(", type: ") + std::string(typeName_) + std::string(", value: '") + val + std::string("'")
, id_
, mtrc
)
, typeName(typeName_)
, value(val)
{}
generic_serialization_error( const char *errName, const std::string &errMsg, const char *typeName_, const std::string &val, int id_ = 0, const std::string &mtrc="marty_cpp" )
: base_error( errName
, errMsg + std::string(", type: ") + std::string(typeName_) + std::string(", value: '") + val + std::string("'")
, id_
, mtrc
)
, typeName(typeName_)
, value(val)
{}
generic_serialization_error(const generic_serialization_error &e)
: base_error(e)
, typeName(e.typeName)
, value(e.value)
{}
generic_serialization_error& operator=(const generic_serialization_error& e) = delete;
};
class enum_deserialization_error : public generic_serialization_error
{
public:
enum_deserialization_error(const char *typeName_, const std::string &val, int id_ = 0, const std::string &mtrc="marty_cpp")
: generic_serialization_error("Enum/flags deserialization error", "Failed to deserialize value", typeName_, val, id_, mtrc)
{}
enum_deserialization_error(const enum_deserialization_error &e)
: generic_serialization_error(e)
{}
enum_deserialization_error& operator=(const enum_deserialization_error& e) = delete;
};
} // namespace marty_cpp