Update method_missing support to reduce exceptions
This commit is contained in:
@@ -831,9 +831,19 @@ namespace chaiscript
|
|||||||
if (is_attribute_call(funs, params, t_has_params)) {
|
if (is_attribute_call(funs, params, t_has_params)) {
|
||||||
return do_attribute_call(1, params, funs, m_conversions);
|
return do_attribute_call(1, params, funs, m_conversions);
|
||||||
} else {
|
} else {
|
||||||
|
std::exception_ptr except;
|
||||||
|
|
||||||
|
if (!funs.empty()) {
|
||||||
try {
|
try {
|
||||||
return dispatch::dispatch(funs, params, m_conversions);
|
return dispatch::dispatch(funs, params, m_conversions);
|
||||||
} catch(chaiscript::exception::dispatch_error&) {
|
} 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 auto functions = get_function("method_missing");
|
||||||
|
|
||||||
const bool is_no_param = [&]()->bool{
|
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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user