This repository was archived by the owner on Nov 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCalcASTException.hpp
More file actions
64 lines (53 loc) · 1.44 KB
/
CalcASTException.hpp
File metadata and controls
64 lines (53 loc) · 1.44 KB
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
#include <utility>
#ifndef CALCULATOR_CALCASTEXCEPTION_HPP
#define CALCULATOR_CALCASTEXCEPTION_HPP
#include <string>
#include "Token.hpp"
#include "boilerplate/ld_boilerplate.hpp"
/**
* An exception that is raised when the calculator just doesn't like something.
*
* This can be raised by any step in reality - tokenization step, AST
* generation, or actual execution. Where it raises doesn't matter - what
* matters is the token that _raised_ the exception, which this class
* conveniently stores for any from of pretty-printing that you'd like to
* perform.
*/
class CalcASTException : public std::exception {
/**
* The token that caused the exception
*/
Token token;
/**
* A user-friendly message that specifies what went wrong
*/
std::wstring msg;
public:
CalcASTException(Token token, std::wstring msg) : token(std::move(token)),
msg(std::move(msg)) {}
/**
* Gets the token that caused the exception.
*
* @return The token
*/
Token get_token() const {
return token;
}
/**
* Gets the user-friendly message that caused the exception.
*
* @return
*/
std::wstring get_msg() const {
return msg;
}
/**
* Don't use this. It returns a C string, which is no fun. :<
*
* @return The boring C string version of [[CalcASTException::get_msg]].
*/
const char * what() const noexcept {
return LD::w2str(msg).c_str();
}
};
#endif //CALCULATOR_CALCASTEXCEPTION_HPP