Skip to content

Commit

Permalink
better error message for type error
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed Feb 20, 2018
1 parent c77b514 commit 99b8ddb
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/shogun/base/SGObject.h
Expand Up @@ -346,16 +346,20 @@ class CSGObject
{
if (has_parameter(_tag))
{
if(has<T>(_tag.name()))
try
{
ref_value(&value);
update_parameter(_tag, make_any(value));
any_cast<T>(get_parameter(_tag).get_value());
}
else
catch (const TypeMismatchException& exc)
{
SG_ERROR("Type for parameter with name \"%s\" is not correct.\n",
_tag.name().c_str());
SG_ERROR(
"Setting parameter %s::%s failed. Provided type is %s, but "
"actual type is %s.\n",
get_name(), _tag.name().c_str(), exc.expected().c_str(),
exc.actual().c_str());
}
ref_value(&value);
update_parameter(_tag, make_any(value));
}
else
{
Expand Down Expand Up @@ -397,9 +401,10 @@ class CSGObject
catch (const TypeMismatchException& exc)
{
SG_ERROR(
"Get \"%s\" failed. Expected %s, got %s.\n",
_tag.name().c_str(), exc.expected().c_str(),
exc.actual().c_str());
"Getting parameter %s::%s failed. Requested type is %s, "
"but actual type is %s.\n",
get_name(), _tag.name().c_str(), exc.actual().c_str(),
exc.expected().c_str());
}
// we won't be there
return any_cast<T>(value);
Expand Down

0 comments on commit 99b8ddb

Please sign in to comment.