diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 9a87c8b..5dcc4a8 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -408,6 +408,12 @@ namespace chaiscript m->add(fun(return_boxed_value_vector(&dispatch::Proxy_Function_Base::get_contained_functions)), "get_contained_functions"); + m->add(user_type(), "out_of_range"); + m->add(user_type(), "logic_error"); + m->add(chaiscript::base_class()); + m->add(chaiscript::base_class()); + m->add(chaiscript::base_class()); + m->add(user_type(), "runtime_error"); m->add(chaiscript::base_class()); diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index 650124c..a763e48 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -438,9 +438,13 @@ namespace chaiscript m->add(user_type(), type); typedef typename MapType::mapped_type &(MapType::*elem_access)(const typename MapType::key_type &); + typedef const typename MapType::mapped_type &(MapType::*const_elem_access)(const typename MapType::key_type &) const; m->add(fun(static_cast(&MapType::operator[])), "[]"); + m->add(fun(static_cast(&MapType::at)), "at"); + m->add(fun(static_cast(&MapType::at)), "at"); + container_type(type, m); default_constructible_type(type, m); assignable_type(type, m); diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index 49b80cb..32ebe60 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -878,7 +878,7 @@ namespace chaiscript } std::stable_sort(ordered_funcs.begin(), ordered_funcs.end(), - [](const decltype(ordered_funcs)::const_reference &t_lhs, const decltype(ordered_funcs)::const_reference &t_rhs) + [](decltype(ordered_funcs)::const_reference t_lhs, decltype(ordered_funcs)::const_reference t_rhs) { return t_lhs.first < t_rhs.first; } diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 895dcad..37df850 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -1340,9 +1340,14 @@ namespace chaiscript } throw; } + catch (const std::runtime_error &e) { + retval = handle_exception(t_ss, Boxed_Value(std::ref(e))); + } + catch (const std::out_of_range &e) { + retval = handle_exception(t_ss, Boxed_Value(std::ref(e))); + } catch (const std::exception &e) { retval = handle_exception(t_ss, Boxed_Value(std::ref(e))); - } catch (Boxed_Value &e) { retval = handle_exception(t_ss, e); diff --git a/unittests/map_access.chai b/unittests/map_access.chai index d544036..1b2d73f 100644 --- a/unittests/map_access.chai +++ b/unittests/map_access.chai @@ -1,2 +1,19 @@ auto x = ["bob":2, "fred":3] assert_equal(3, x["fred"]) + + +try { + auto m = ["bob":2, "fred":3]; + m.at("tom"); + assert_true(false); +} catch (out_of_range e) { + print("out_of_range") + assert_true(true); +} catch (e) { + print("other") + dump_object(e); + assert_true(false); +} + + +assert_equal(["bob":2, "fred":3].at("fred"), 3);