-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathError.cpp
More file actions
29 lines (26 loc) · 873 Bytes
/
Copy pathError.cpp
File metadata and controls
29 lines (26 loc) · 873 Bytes
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
#include "Error.h"
Error::Error(const string& msg, const int line = -1, const int count = -1){
this->msg = msg;
this->line = line;
this->count = count;
set_name("Error");
}
void Error::set_name(const string &name){
what_str = "";
if(line != -1 && count != -1){
what_str += std::to_string(line) + ":" + std::to_string(count) + ": ";
}
what_str += name + ": " + msg;
}
const char* Error::what() const throw(){
return what_str.c_str();
}
#define DEFINE_ERROR_CLASS_CONSTRUCTER(name) \
name::name(const string& msg, const int line, const int count) : Error(msg, line, count){ \
set_name(#name); \
}
DEFINE_ERROR_CLASS_CONSTRUCTER(SyntaxError)
DEFINE_ERROR_CLASS_CONSTRUCTER(FileNotFoundError)
DEFINE_ERROR_CLASS_CONSTRUCTER(TypeError)
DEFINE_ERROR_CLASS_CONSTRUCTER(NameError)
DEFINE_ERROR_CLASS_CONSTRUCTER(ZeroDivisionError)