Skip to content

Commit

Permalink
Better exception handling (#4064)
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Jan 3, 2018
1 parent bdda91b commit 3ac662c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/interfaces/python/swig_typemaps.i
Expand Up @@ -1276,4 +1276,11 @@ TYPEMAP_SPARSEFEATURES_OUT(complex128_t, NPY_CDOUBLE)
TYPEMAP_SPARSEFEATURES_OUT(floatmax_t, NPY_LONGDOUBLE)
TYPEMAP_SPARSEFEATURES_OUT(PyObject, NPY_OBJECT)
#undef TYPEMAP_SPARSEFEATURES_OUT

%typemap(throws) shogun::ShogunException
{
PyErr_SetString(PyExc_RuntimeError, $1.get_exception_string());
SWIG_fail;
}

#endif /* HAVE_PYTHON */
2 changes: 1 addition & 1 deletion src/interfaces/swig/SGBase.i
Expand Up @@ -306,6 +306,7 @@ public void readExternal(java.io.ObjectInput in) throws java.io.IOException, jav
%rename(SGObject) CSGObject;

%include <shogun/lib/common.h>
%include <shogun/lib/ShogunException.h>

%include "swig_typemaps.i"

Expand Down Expand Up @@ -509,7 +510,6 @@ copy_reg._reconstructor=_sg_reconstructor

%include <shogun/lib/basetag.h>
%include <shogun/lib/tag.h>
%include <shogun/lib/ShogunException.h>
%include <shogun/base/SGObject.h>

%define SUPPORT_TAG(camel_type, short_type, type)
Expand Down
6 changes: 3 additions & 3 deletions src/shogun/base/SGObject.h
Expand Up @@ -381,10 +381,10 @@ class CSGObject
{
return recall_type<T>(value);
}
catch (const std::logic_error&)
catch (const std::logic_error& exc)
{
SG_ERROR("Type for parameter with name \"%s\" is not correct in \"%s\".\n",
_tag.name().c_str(), get_name());
SG_ERROR(
"Get \"%s\" failed: %s.\n", _tag.name().c_str(), exc.what());
}
// we won't be there
return recall_type<T>(value);
Expand Down

0 comments on commit 3ac662c

Please sign in to comment.