Originally Posted by
phantomotap
Don't catch exceptions by value!
Oops.. slipped.
This function says that the list is valid if, for example, allocation from `new' fails.
What new ? ...isn't the memory for 'l' already there?
If the constructor fails for any reason other than "this string is not a list" the constructor has to raise an exception. Why do you want a special case to ask a question that can be more truly answered using a different method?
Consider this usage of the checking:
Code:
std::string setv(list& l)
{
if(l.size()!=2)throw(exception("BAD_SETV"));
std::string name=l.car(),value=l.cdr().car();
list result;
if(is_list(value,result))value=result.eval();
auto v = var_scope.find(name);
if(v!=nullptr)*v = value;
else var_scope.new_global_val(name,value);
return name;
}
//VS
std::string setv(list& l)
{
if(l.size()!=2)throw(exception("BAD_SETV"));
std::string name=l.car(),value=l.cdr().car();
bool test(true);
list result(value,test);
if(test) value=result.eval();
auto v = var_scope.find(name);
if(v!=nullptr)*v = value;
else var_scope.new_global_val(name,value);
return name;
}
My point is that, the function itself calls the constructor...so all the potential problems remain same....other exceptions will propagate downwards the same way.