From c8a58c1c34bb1a0ea2360628518457ded9f7aa19 Mon Sep 17 00:00:00 2001 From: Igor Danielewicz <igor.danielewicz@pwr.edu.pl> Date: Tue, 12 Jun 2018 12:27:31 +0200 Subject: [PATCH] Swig rethrows c++ runtime exception (xmlp::parse_error) to python. --- swig/annotatedsentence.i | 2 +- swig/cclrelreader.i | 7 ++++++- swig/corpus2.i | 2 +- swig/{exception.i => corpus2exception.i} | 2 ++ swig/tagset.i | 2 +- swig/tagsetmanager.i | 2 +- 6 files changed, 12 insertions(+), 5 deletions(-) rename swig/{exception.i => corpus2exception.i} (97%) diff --git a/swig/annotatedsentence.i b/swig/annotatedsentence.i index 9aff2b8..f6488c5 100644 --- a/swig/annotatedsentence.i +++ b/swig/annotatedsentence.i @@ -8,7 +8,7 @@ %include "token.i" %include "sentence.i" -%include "exception.i" +%include "corpus2exception.i" %include "annotationchannel.i" %include "boost_shared_ptr.i" diff --git a/swig/cclrelreader.i b/swig/cclrelreader.i index 6c53cc6..c15fb41 100644 --- a/swig/cclrelreader.i +++ b/swig/cclrelreader.i @@ -6,7 +6,8 @@ #include <libcorpus2_whole/io/cclrelreader.h> %} -%include "exception.i" +%include <exception.i> +%include "corpus2exception.i" %include "document.i" %include "boost_shared_ptr.i" @@ -32,6 +33,10 @@ namespace whole { } catch (PwrNlp::PwrNlpError &e) { PyErr_SetString(PyExc_IndexError, e.info().c_str()); return NULL; + } catch (xmlpp::parse_error &e) { + std::string s("xmlpp::parse_error: "), s2(e.what()); + s = s + s2; + SWIG_exception(SWIG_RuntimeError, s.c_str()); } } boost::shared_ptr<Document> read(); diff --git a/swig/corpus2.i b/swig/corpus2.i index 5e8267a..2819ccd 100755 --- a/swig/corpus2.i +++ b/swig/corpus2.i @@ -5,7 +5,7 @@ %include "boost_shared_ptr.i" %include "unicodestring.i" -%include "exception.i" +%include "corpus2exception.i" %include "annotatedsentence.i" %include "annotationchannel.i" %include "annotationview.i" diff --git a/swig/exception.i b/swig/corpus2exception.i similarity index 97% rename from swig/exception.i rename to swig/corpus2exception.i index 27a97ce..ccab291 100644 --- a/swig/exception.i +++ b/swig/corpus2exception.i @@ -1,6 +1,8 @@ #ifndef SWIG_LIBCORPUS2_EXCEPTION_I #define SWIG_LIBCORPUS2_EXCEPTION_I +%include <exception.i> + %module libcorpusexception %{ #include <libcorpus2/exception.h> diff --git a/swig/tagset.i b/swig/tagset.i index dc77bfe..9768c94 100644 --- a/swig/tagset.i +++ b/swig/tagset.i @@ -6,7 +6,7 @@ #include <libcorpus2/tagset.h> %} %include "tag.i" -%include "exception.i" +%include "corpus2exception.i" %include "std_defs.i" %include "std_string.i" diff --git a/swig/tagsetmanager.i b/swig/tagsetmanager.i index 4b690cb..865a186 100644 --- a/swig/tagsetmanager.i +++ b/swig/tagsetmanager.i @@ -7,7 +7,7 @@ %} %include "tagset.i" -%include "exception.i" +%include "corpus2exception.i" %include "std_string.i" %include "std_vector.i" -- GitLab