Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better exception handling #4064

Merged
merged 1 commit into from
Jan 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/interfaces/python/swig_typemaps.i
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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