ArkScript
A small, fast, functional and scripting language for video games
Exceptions.hpp
Go to the documentation of this file.
1/**
2 * @file Exceptions.hpp
3 * @author Alexandre Plateau ([email protected]), Max ([email protected])
4 * @brief ArkScript homemade exceptions
5 * @version 0.2
6 * @date 2020-10-27
7 *
8 * @copyright Copyright (c) 2020-2021
9 *
10 */
11
12#ifndef INCLUDE_ARK_EXCEPTIONS_HPP
13#define INCLUDE_ARK_EXCEPTIONS_HPP
14
15#include <exception>
16#include <string>
17#include <vector>
18#include <stdexcept>
19
20#include <Ark/VM/Value.hpp>
21
22namespace Ark
23{
24 /**
25 * @brief A type error triggered when types don't match
26 *
27 */
28 class TypeError : public std::runtime_error
29 {
30 public:
31 explicit TypeError(const std::string& message) :
32 std::runtime_error(message)
33 {}
34 };
35
36 /**
37 * @brief A special zero division error triggered when a number is divided by 0
38 *
39 */
40 class ZeroDivisionError : public std::runtime_error
41 {
42 public:
44 std::runtime_error(
45 "ZeroDivisionError: In ordonary arithmetic, the expression has no meaning, "
46 "as there is no number which, when multiplied by 0, gives a (assuming a != 0), "
47 "and so division by zero is undefined. Since any number multiplied by 0 is 0, "
48 "the expression 0/0 is also undefined.")
49 {}
50 };
51
52 /**
53 * @brief A pow error triggered when we can't do a pow b
54 *
55 */
56 class PowError : public std::runtime_error
57 {
58 public:
60 std::runtime_error(
61 "PowError: Can not pow the given number (a) to the given exponent (b) because "
62 "a^b, with b being a member of the rational numbers, isn't supported.")
63 {}
64 };
65
66 /**
67 * @brief An assertion error, only triggered from ArkScript code through (assert expr error-message)
68 *
69 */
70 class AssertionFailed : public std::runtime_error
71 {
72 public:
73 explicit AssertionFailed(const std::string& message) :
74 std::runtime_error("AssertionFailed: " + message)
75 {}
76 };
77
78 /**
79 * @brief SyntaxError thrown by the lexer
80 *
81 */
82 class SyntaxError : public std::runtime_error
83 {
84 public:
85 explicit SyntaxError(const std::string& message) :
86 std::runtime_error("SyntaxError: " + message)
87 {}
88 };
89
90 /**
91 * @brief ParseError thrown by the parser
92 *
93 */
94 class ParseError : public std::runtime_error
95 {
96 public:
97 explicit ParseError(const std::string& message) :
98 std::runtime_error("ParseError: " + message)
99 {}
100 };
101
102 /**
103 * @brief OptimizerError thrown by the AST optimizer
104 *
105 */
106 class OptimizerError : public std::runtime_error
107 {
108 public:
109 explicit OptimizerError(const std::string& message) :
110 std::runtime_error("OptimizerError: " + message)
111 {}
112 };
113
114 /**
115 * @brief MacroProcessingError thrown by the compiler
116 *
117 */
118 class MacroProcessingError : public std::runtime_error
119 {
120 public:
121 explicit MacroProcessingError(const std::string& message) :
122 std::runtime_error("MacroProcessingError: " + message)
123 {}
124 };
125
126 /**
127 * @brief CompilationError thrown by the compiler
128 *
129 */
130 class CompilationError : public std::runtime_error
131 {
132 public:
133 explicit CompilationError(const std::string& message) :
134 std::runtime_error("CompilationError: " + message)
135 {}
136 };
137}
138
139#endif
An assertion error, only triggered from ArkScript code through (assert expr error-message)
Definition: Exceptions.hpp:71
AssertionFailed(const std::string &message)
Definition: Exceptions.hpp:73
CompilationError thrown by the compiler.
Definition: Exceptions.hpp:131
CompilationError(const std::string &message)
Definition: Exceptions.hpp:133
MacroProcessingError thrown by the compiler.
Definition: Exceptions.hpp:119
MacroProcessingError(const std::string &message)
Definition: Exceptions.hpp:121
OptimizerError thrown by the AST optimizer.
Definition: Exceptions.hpp:107
OptimizerError(const std::string &message)
Definition: Exceptions.hpp:109
ParseError thrown by the parser.
Definition: Exceptions.hpp:95
ParseError(const std::string &message)
Definition: Exceptions.hpp:97
A pow error triggered when we can't do a pow b.
Definition: Exceptions.hpp:57
SyntaxError thrown by the lexer.
Definition: Exceptions.hpp:83
SyntaxError(const std::string &message)
Definition: Exceptions.hpp:85
A type error triggered when types don't match.
Definition: Exceptions.hpp:29
TypeError(const std::string &message)
Definition: Exceptions.hpp:31
A special zero division error triggered when a number is divided by 0.
Definition: Exceptions.hpp:41
Definition: Builtins.hpp:21