MCPcopy Create free account
hub / github.com/ChaiScript/ChaiScript / eval_error

Class eval_error

include/chaiscript/language/chaiscript_common.hpp:168–477  ·  view source on GitHub ↗

Errors generated during parsing or evaluation

Source from the content-addressed store, hash-verified

166
167 /// Errors generated during parsing or evaluation
168 struct eval_error : std::runtime_error {
169 std::string reason;
170 File_Position start_position;
171 std::string filename;
172 std::string detail;
173 std::vector<AST_Node_Trace> call_stack;
174
175 eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname,
176 const std::vector<Boxed_Value> &t_parameters, const std::vector<chaiscript::Const_Proxy_Function> &t_functions,
177 bool t_dot_notation,
178 const chaiscript::detail::Dispatch_Engine &t_ss) noexcept :
179 std::runtime_error(format(t_why, t_where, t_fname, t_parameters, t_dot_notation, t_ss)),
180 reason(t_why), start_position(t_where), filename(t_fname), detail(format_detail(t_functions, t_dot_notation, t_ss))
181 {}
182
183 eval_error(const std::string &t_why,
184 const std::vector<Boxed_Value> &t_parameters, const std::vector<chaiscript::Const_Proxy_Function> &t_functions,
185 bool t_dot_notation,
186 const chaiscript::detail::Dispatch_Engine &t_ss) noexcept :
187 std::runtime_error(format(t_why, t_parameters, t_dot_notation, t_ss)),
188 reason(t_why), detail(format_detail(t_functions, t_dot_notation, t_ss))
189 {}
190
191
192 eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) noexcept :
193 std::runtime_error(format(t_why, t_where, t_fname)),
194 reason(t_why), start_position(t_where), filename(t_fname)
195 {}
196
197 explicit eval_error(const std::string &t_why) noexcept
198 : std::runtime_error("Error: \"" + t_why + "\" "),
199 reason(t_why)
200 {}
201
202 eval_error(const eval_error &) = default;
203
204 std::string pretty_print() const
205 {
206 std::ostringstream ss;
207
208 ss << what();
209 if (!call_stack.empty()) {
210 ss << "during evaluation at (" << fname(call_stack[0]) << " " << startpos(call_stack[0]) << ")\n";
211 ss << '\n' << detail << '\n';
212 ss << " " << fname(call_stack[0]) << " (" << startpos(call_stack[0]) << ") '" << pretty(call_stack[0]) << "'";
213 for (size_t j = 1; j < call_stack.size(); ++j) {
214 if (id(call_stack[j]) != chaiscript::AST_Node_Type::Block
215 && id(call_stack[j]) != chaiscript::AST_Node_Type::File)
216 {
217 ss << '\n';
218 ss << " from " << fname(call_stack[j]) << " (" << startpos(call_stack[j]) << ") '" << pretty(call_stack[j]) << "'";
219 }
220 }
221 }
222 ss << '\n';
223 return ss.str();
224 }
225

Callers 15

Depth_CounterMethod · 0.85
validate_object_nameMethod · 0.85
SkipWSMethod · 0.85
Id_Method · 0.85
Quoted_String_Method · 0.85
process_unicodeMethod · 0.85
parseMethod · 0.85
Quoted_StringMethod · 0.85
Single_Quoted_String_Method · 0.85
Single_Quoted_StringMethod · 0.85
Id_Arg_ListMethod · 0.85
Decl_Arg_ListMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected