From b17c6b9748622e5ade322517db931934a5e8c9f3 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Fri, 18 Sep 2009 22:26:07 +0000 Subject: [PATCH] Add support for std::exception and what() --- include/chaiscript/dispatchkit/bootstrap.hpp | 1 + .../chaiscript/language/chaiscript_eval.hpp | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 95afb03..b79d132 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -674,6 +674,7 @@ namespace chaiscript m->add(fun(&to_string), "internal_to_string"); m->add(fun(&unknown_assign), "="); m->add(fun(&throw_exception), "throw"); + m->add(fun(&what), "what"); bootstrap_pod_type("double", m); bootstrap_pod_type("int", m); diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 04e600c..9cdc29e 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -591,9 +591,21 @@ namespace chaiscript try { retval = eval_token(ss, node->children[0]); } - catch (std::exception &) { - // nothing - std::cout << "DEBUG: std::exception caught" << std::endl; + catch (const Eval_Error &) { + throw; + } + catch (const std::exception &e) { + if (node->children.size() > 2) { + if (node->children[1]->text == "catch") { + if (node->children.size() > 3) { + ss.add_object(node->children[2]->text, Boxed_Value(boost::ref(e))); + retval = eval_token(ss, node->children[3]); + } + else { + retval = eval_token(ss, node->children[2]); + } + } + } } catch (Boxed_Value &bv) { if (node->children.size() > 2) {