Update method_missing support to reduce exceptions

This commit is contained in:
Jason Turner
2015-04-22 12:15:15 -06:00
parent f3943f215f
commit a542ec01f6

View File

@@ -831,9 +831,19 @@ namespace chaiscript
if (is_attribute_call(funs, params, t_has_params)) {
return do_attribute_call(1, params, funs, m_conversions);
} else {
std::exception_ptr except;
if (!funs.empty()) {
try {
return dispatch::dispatch(funs, params, m_conversions);
} catch(chaiscript::exception::dispatch_error&) {
except = std::current_exception();
}
}
// If we get here we know that either there was no method with that name,
// or there was no matching method
const auto functions = get_function("method_missing");
const bool is_no_param = [&]()->bool{
@@ -855,7 +865,12 @@ namespace chaiscript
}
}
throw;
// If we get all the way down here we know there was no "method_missing"
// method at all.
if (except) {
std::rethrow_exception(except);
} else {
throw chaiscript::exception::dispatch_error(params, std::vector<Const_Proxy_Function>(funs.begin(), funs.end()));
}
}
}