From 7173ad1fb2c19a0525ec004aa3011319bf39c6fc Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Tue, 13 Feb 2018 16:27:06 +0000 Subject: [PATCH] better error message for type error --- src/shogun/base/SGObject.h | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/shogun/base/SGObject.h b/src/shogun/base/SGObject.h index 3c6f58fabef..832863f8f8b 100644 --- a/src/shogun/base/SGObject.h +++ b/src/shogun/base/SGObject.h @@ -346,16 +346,20 @@ class CSGObject { if (has_parameter(_tag)) { - if(has(_tag.name())) + try { - ref_value(&value); - update_parameter(_tag, make_any(value)); + any_cast(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 { @@ -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(value);