Reduce exceptions on startup to minimum

This still has some exceptions thrown during the loading of modules
since I have no way of knowing where the operating system
`dlopen` and `LoadLibrary` functions will search for me to pre-check
it.

Closes #158
This commit is contained in:
Jason Turner
2015-04-06 13:17:41 -06:00
parent f953f9b297
commit 962bdf4b3c
6 changed files with 39 additions and 36 deletions

View File

@@ -517,11 +517,7 @@ namespace chaiscript
{
return std::pair<std::string, Type_Info>();
} else {
try {
return std::pair<std::string, Type_Info>(t_node->children[0]->text, t_ss.get_type(t_node->children[0]->text));
} catch (const std::range_error &) {
return std::pair<std::string, Type_Info>(t_node->children[0]->text, Type_Info());
}
return std::pair<std::string, Type_Info>(t_node->children[0]->text, t_ss.get_type(t_node->children[0]->text, false));
}
}
@@ -1484,30 +1480,19 @@ namespace chaiscript
static_cast<int>(numparams), this->children.back(), param_types, l_annotation, guard)),
function_name);
}
else {
try {
// Do know type name (if this line fails, the catch block is called and the
// other version is called, with no Type_Info object known)
auto type = t_ss.get_type(class_name);
param_types.push_front(class_name, type);
} else {
t_ss.add(
std::make_shared<dispatch::detail::Dynamic_Object_Function>(class_name,
std::make_shared<dispatch::Dynamic_Proxy_Function>(std::bind(chaiscript::eval::detail::eval_function,
std::ref(t_ss), this->children.back(),
t_param_names, std::placeholders::_1, std::map<std::string, Boxed_Value>()), static_cast<int>(numparams), this->children.back(),
param_types, l_annotation, guard), type), function_name);
} catch (const std::range_error &) {
param_types.push_front(class_name, Type_Info());
// Do not know type name
t_ss.add(
std::make_shared<dispatch::detail::Dynamic_Object_Function>(class_name,
std::make_shared<dispatch::Dynamic_Proxy_Function>(std::bind(chaiscript::eval::detail::eval_function,
std::ref(t_ss), this->children.back(),
t_param_names, std::placeholders::_1, std::map<std::string, Boxed_Value>()), static_cast<int>(numparams), this->children.back(),
param_types, l_annotation, guard)), function_name);
}
// if the type is unknown, then this generates a function that looks up the type
// at runtime. Defining the type first before this is called is better
auto type = t_ss.get_type(class_name, false);
param_types.push_front(class_name, type);
t_ss.add(
std::make_shared<dispatch::detail::Dynamic_Object_Function>(class_name,
std::make_shared<dispatch::Dynamic_Proxy_Function>(std::bind(chaiscript::eval::detail::eval_function,
std::ref(t_ss), this->children.back(),
t_param_names, std::placeholders::_1, std::map<std::string, Boxed_Value>()), static_cast<int>(numparams), this->children.back(),
param_types, l_annotation, guard), type), function_name);
}
}
catch (const exception::reserved_word_error &e) {