Cleaned up exception story
This commit is contained in:
parent
aa0f54c53f
commit
06604e14b5
@ -45,15 +45,8 @@ namespace chaiscript
|
||||
*/
|
||||
const dispatchkit::Boxed_Value eval(const std::vector<dispatchkit::Boxed_Value> &vals) {
|
||||
std::string val;
|
||||
try {
|
||||
val = dispatchkit::boxed_cast<std::string &>(vals[0]);
|
||||
}
|
||||
catch (Eval_Error &ee) {
|
||||
throw Eval_Error("Can not evaluate string: " + val + " reason: " + ee.reason, TokenPtr());
|
||||
}
|
||||
catch (std::exception &) {
|
||||
throw Eval_Error("Can not evaluate string: " + val, TokenPtr());
|
||||
}
|
||||
val = dispatchkit::boxed_cast<std::string &>(vals[0]);
|
||||
|
||||
return evaluate_string(val);
|
||||
}
|
||||
|
||||
@ -112,20 +105,6 @@ namespace chaiscript
|
||||
catch (const Return_Value &rv) {
|
||||
value = rv.retval;
|
||||
}
|
||||
catch (Parse_Error &pe) {
|
||||
std::cout << pe.reason << " in " << pe.filename << " at " << pe.position.line << ", " << pe.position.column << std::endl;
|
||||
}
|
||||
catch (Eval_Error &ee) {
|
||||
if (filename != std::string("__EVAL__")) {
|
||||
std::cout << "Eval error: \"" << ee.reason << "\" in '" << ee.location->filename << "' line: " << ee.location->start.line << std::endl;
|
||||
}
|
||||
else {
|
||||
std::cout << "Eval error: \"" << ee.reason << "\"" << std::endl;
|
||||
}
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
@ -422,7 +422,7 @@ namespace chaiscript
|
||||
}
|
||||
catch(const dispatchkit::dispatch_error &e){
|
||||
ss.set_stack(prev_stack);
|
||||
throw Eval_Error("Engine error: " + std::string(e.what()) + " with function '" + node->children[0]->text + "'", node->children[0]);
|
||||
throw Eval_Error(std::string(e.what()) + " with function '" + node->children[0]->text + "'", node->children[0]);
|
||||
}
|
||||
catch(Return_Value &rv) {
|
||||
ss.set_stack(prev_stack);
|
||||
@ -477,9 +477,9 @@ namespace chaiscript
|
||||
retval = dispatch(fn, plb);
|
||||
ss.set_stack(prev_stack);
|
||||
}
|
||||
catch(const dispatchkit::dispatch_error &){
|
||||
catch(const dispatchkit::dispatch_error &e){
|
||||
ss.set_stack(prev_stack);
|
||||
throw Eval_Error("Can not find appropriate '" + fun_name + "'", node);
|
||||
throw Eval_Error(std::string(e.what()) + " with function '" + fun_name + "'", node->children[i]);
|
||||
}
|
||||
catch(Return_Value &rv) {
|
||||
ss.set_stack(prev_stack);
|
||||
|
@ -10,11 +10,9 @@ void print_help() {
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
|
||||
std::string input;
|
||||
|
||||
chaiscript::ChaiScript_Engine chai;
|
||||
|
||||
chai.build_eval_system();
|
||||
|
||||
if (argc < 2) {
|
||||
@ -28,15 +26,29 @@ int main(int argc, char *argv[]) {
|
||||
print_help();
|
||||
}
|
||||
else {
|
||||
val = chai.evaluate_string(input);
|
||||
try {
|
||||
//First, we evaluate it
|
||||
val = chai.evaluate_string(input);
|
||||
|
||||
if (val.get_type_info().m_bare_type_info && *(val.get_type_info().m_bare_type_info) != typeid(void)) {
|
||||
try {
|
||||
dispatchkit::dispatch(chai.get_eval_engine().get_function("print"), dispatchkit::Param_List_Builder() << val);
|
||||
} catch (const std::runtime_error &e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
//Then, we try to print the result of the evaluation to the user
|
||||
if (val.get_type_info().m_bare_type_info && *(val.get_type_info().m_bare_type_info) != typeid(void)) {
|
||||
try {
|
||||
dispatchkit::dispatch(chai.get_eval_engine().get_function("print"), dispatchkit::Param_List_Builder() << val);
|
||||
}
|
||||
catch (...) {
|
||||
//If we can't, do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (chaiscript::Parse_Error &pe) {
|
||||
std::cout << pe.reason << " in " << pe.filename << " at " << pe.position.line << ", " << pe.position.column << std::endl;
|
||||
}
|
||||
catch (chaiscript::Eval_Error &ee) {
|
||||
std::cout << ee.reason << std::endl;
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "eval> ";
|
||||
@ -45,12 +57,28 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
else {
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
std::string filename(argv[i]);
|
||||
try {
|
||||
dispatchkit::Boxed_Value val = chai.evaluate_file(argv[i]);
|
||||
}
|
||||
catch (std::exception &) {
|
||||
std::cerr << "Could not open: " << argv[i] << std::endl;
|
||||
exit(1);
|
||||
catch (chaiscript::Parse_Error &pe) {
|
||||
if (filename != std::string("__EVAL__")) {
|
||||
std::cout << pe.reason << " in " << pe.filename << " at " << pe.position.line << ", " << pe.position.column << std::endl;
|
||||
}
|
||||
else {
|
||||
std::cout << pe.reason << std::endl;
|
||||
}
|
||||
}
|
||||
catch (chaiscript::Eval_Error &ee) {
|
||||
if (filename != std::string("__EVAL__")) {
|
||||
std::cout << ee.reason << " in '" << ee.location->filename << "' at " << ee.location->start.line << ", " << ee.location->start.column << std::endl;
|
||||
}
|
||||
else {
|
||||
std::cout << ee.reason << std::endl;
|
||||
}
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user