-
Notifications
You must be signed in to change notification settings - Fork 0
/
Error.h
38 lines (32 loc) · 954 Bytes
/
Error.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
#pragma once
#include <string>
#include "Token.h"
using namespace std;
class Error: public exception{
public:
string msg, what_str;
int line, count;
Error(){}
Error(const string&, const int, const int);
Error(const string& msg) :
Error(msg, -1, -1){}
Error(const string& msg, const Token& token) :
Error(msg, token.line, token.count){}
void set_name(const string &);
const char* what() const throw() override;
};
#define DEFINE_ERROR_CLASS(name) \
class name : public Error{ \
public: \
name() : Error(){} \
name(const string&, const int, const int); \
name(const string& msg) : \
name(msg, -1, -1){} \
name(const string& msg, const Token& token) : \
name(msg, token.line, token.count){} \
};
DEFINE_ERROR_CLASS(SyntaxError)
DEFINE_ERROR_CLASS(FileNotFoundError)
DEFINE_ERROR_CLASS(TypeError)
DEFINE_ERROR_CLASS(NameError)
DEFINE_ERROR_CLASS(ZeroDivisionError)