From 7e046918647bd4b26d5f5713b492be4bedffb20a Mon Sep 17 00:00:00 2001 From: michal <michal@kalafior.(none)> Date: Mon, 18 Mar 2013 15:00:39 +0100 Subject: [PATCH] added python wrappers for wccl exceptions --- CMakeLists.txt | 2 +- swig/exception.i | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 swig/exception.i diff --git a/CMakeLists.txt b/CMakeLists.txt index 028b4e2..47c667d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.0) set(wccl_ver_major "0") set(wccl_ver_minor "3") -set(wccl_ver_patch "1") +set(wccl_ver_patch "2") set(LIBWCCL_VERSION "${wccl_ver_major}.${wccl_ver_minor}.${wccl_ver_patch}") diff --git a/swig/exception.i b/swig/exception.i new file mode 100644 index 0000000..320866e --- /dev/null +++ b/swig/exception.i @@ -0,0 +1,51 @@ +#ifndef LIBWCCL_EXCEPTION_H +#define LIBWCCL_EXCEPTION_H + +%module libcorpusexception +%{ + #include <libpwrutils/exception.h> +%} + +%include "std_string.i" + +%include "libpwrnlperror.i" + +namespace Wccl { + class WcclError : public PwrNlp::PwrNlpError { + public: + WcclError(const std::string &what); + ~WcclError() throw(); + + /* --------------------------------------------------------------------- */ + std::string scope() const; + }; + + class InvalidArgument : public WcclError { + public: + InvalidArgument(const std::string& arg_name, const std::string& reason); + + ~InvalidArgument() throw(); + + /* --------------------------------------------------------------------- */ + std::string info() const; + std::string arg_name; + std::string reason; + }; + + %exception { + try { + $action + } catch (Wccl::InvalidArgument &e) { + PyErr_SetString(PyExc_IndexError, e.info().c_str()); + return NULL; + } catch (PwrNlp::PwrNlpError &e) { + PyErr_SetString(PyExc_IndexError, e.info().c_str()); + return NULL; + } + } +} + +using namespace std; +using namespace Wccl; + +#endif /* SWIG_LIBWCCL_EXCEPTION_I */ \ No newline at end of file -- GitLab