Make EvalError a subclass of runtime_error and provide the std::exception with a robust description for easier debugging of callback/scripted function calls

This commit is contained in:
Jason Turner
2009-06-21 20:07:11 +00:00
parent 786d194689
commit 80ed8eb505
3 changed files with 11 additions and 5 deletions

View File

@@ -29,12 +29,12 @@ namespace chaiscript
try {
val = dispatchkit::Cast_Helper<std::string &>()(vals[0]);
}
catch (std::exception &e) {
throw EvalError("Can not evaluate string: " + val, langkit::TokenPtr());
}
catch (EvalError &ee) {
throw EvalError("Can not evaluate string: " + val + " reason: " + ee.reason, langkit::TokenPtr());
}
catch (std::exception &e) {
throw EvalError("Can not evaluate string: " + val, langkit::TokenPtr());
}
return evaluate_string(val);
}

View File

@@ -15,11 +15,16 @@ namespace chaiscript
ParserError(const std::string &why, const langkit::TokenPtr where) : reason(why), location(where){ }
};
struct EvalError {
struct EvalError : public std::runtime_error {
std::string reason;
langkit::TokenPtr location;
EvalError(const std::string &why, const langkit::TokenPtr where) : reason(why), location(where) { }
EvalError(const std::string &why, const langkit::TokenPtr where)
: std::runtime_error("Eval error: \"" + why + "\" in '"
+ where->filename + "' line: " + boost::lexical_cast<std::string>(where->start.line+1)),
reason(why), location(where) { }
virtual ~EvalError() throw() {}
};
struct ReturnValue {

View File

@@ -4,4 +4,5 @@ cb_handler.add_callbacks( function() { "DivOnePtTwo"; }, function (x) { x / 1.2;
cb_handler.add_callbacks( function() { "DivOnePtTwo"; }, function (x) { blargh; } );