From 4470995bb474687fb15051129dfb501e1c89be4b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pawe=C5=82=20K=C4=99dzia?= <pawel.kedzia@pwr.wroc.pl>
Date: Fri, 13 May 2011 11:49:48 +0200
Subject: [PATCH] (swig) Catch exceptions raised by wcclfile

---
 swig/libcclwcclfile.i | 107 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 107 insertions(+)

diff --git a/swig/libcclwcclfile.i b/swig/libcclwcclfile.i
index 6311ed8..a51db9c 100644
--- a/swig/libcclwcclfile.i
+++ b/swig/libcclwcclfile.i
@@ -88,6 +88,14 @@ namespace Wccl {
     /* --------------------------------------------------------------------- */
 
     // const UntypedOpSequence& get_untyped_section(const std::string& name) const;
+    %exception {
+      try {
+        $action
+      } catch (PwrNlp::PwrNlpError &e) {
+        PyErr_SetString(PyExc_IndexError, e.info().c_str());
+        return NULL;
+      }
+    }
     UntypedOpSequence& get_untyped_section(const std::string& name);
 
     /* --------------------------------------------------------------------- */
@@ -100,12 +108,38 @@ namespace Wccl {
     %template(get_section_position) get_section<Position>;
     %template(get_section_match) get_section<Match>;
     
+    %exception {
+      try {
+        $action
+      } catch (PwrNlp::PwrNlpError &e) {
+        PyErr_SetString(PyExc_IndexError, e.info().c_str());
+        return NULL;
+      }
+    }
     shared_ptr<UntypedOpSequence> get_untyped_section_ptr(const std::string& name);
+
+
+    %exception {
+      try {
+        $action
+      } catch (PwrNlp::PwrNlpError &e) {
+        PyErr_SetString(PyExc_IndexError, e.info().c_str());
+        return NULL;
+      }
+    }
     shared_ptr<const UntypedOpSequence> get_untyped_section_ptr(const std::string& name) const;
     
     /* --------------------------------------------------------------------- */
 
     // template<class T> shared_ptr<const OpSequence<T> > get_section_ptr(const std::string& name) const;
+    %exception {
+      try {
+        $action
+      } catch (PwrNlp::PwrNlpError &e) {
+        PyErr_SetString(PyExc_IndexError, e.info().c_str());
+        return NULL;
+      }
+    }
     template<class T> shared_ptr<OpSequence<T> > get_section_ptr(const std::string& name);
     %template(get_section_ptr_bool) get_section_ptr<Bool>;
     %template(get_section_ptr_tset) get_section_ptr<TSet>;
@@ -116,11 +150,27 @@ namespace Wccl {
     /* --------------------------------------------------------------------- */
 
     // const FunctionalOperator& get_untyped_op(const std::string& name, size_t idx = 0) const;
+    %exception {
+      try {
+        $action
+      } catch (PwrNlp::PwrNlpError &e) {
+        PyErr_SetString(PyExc_IndexError, e.info().c_str());
+        return NULL;
+      }
+    }
     FunctionalOperator& get_untyped_op(const std::string& name, size_t idx = 0);
     
     /* --------------------------------------------------------------------- */
 
     // template<class T> const Operator<T>& get_op(const std::string& name, size_t idx = 0) const;
+    %exception {
+      try {
+        $action
+      } catch (PwrNlp::PwrNlpError &e) {
+        PyErr_SetString(PyExc_IndexError, e.info().c_str());
+        return NULL;
+      }
+    }
     template<class T> Operator<T>& get_op(const std::string& name, size_t idx = 0);
     /*
     %template(get_op_bool) get_op<Bool>;
@@ -133,11 +183,27 @@ namespace Wccl {
     /* --------------------------------------------------------------------- */
 
     // shared_ptr<const FunctionalOperator> get_untyped_op_ptr(const std::string& name, size_t idx = 0) const;
+    %exception {
+      try {
+        $action
+      } catch (PwrNlp::PwrNlpError &e) {
+        PyErr_SetString(PyExc_IndexError, e.info().c_str());
+        return NULL;
+      }
+    }
     shared_ptr<FunctionalOperator> get_untyped_op_ptr(const std::string& name, size_t idx = 0);
 
     /* --------------------------------------------------------------------- */
 
     // template<class T> shared_ptr<const Operator<T> > get_op_ptr(const std::string& name, size_t idx = 0) const;
+    %exception {
+      try {
+        $action
+      } catch (PwrNlp::PwrNlpError &e) {
+        PyErr_SetString(PyExc_IndexError, e.info().c_str());
+        return NULL;
+      }
+    }
     template<class T> shared_ptr<Operator<T> > get_op_ptr(const std::string& name, size_t idx = 0);
     %template(get_op_ptr_bool) get_op_ptr<Bool>;
     %template(get_op_ptr_tset) get_op_ptr<TSet>;
@@ -148,11 +214,27 @@ namespace Wccl {
     /* --------------------------------------------------------------------- */
 
     // UntypedOpSequence::name_op_v_c_t gen_name_untyped_op_pairs() const;
+    %exception {
+      try {
+        $action
+      } catch (PwrNlp::PwrNlpError &e) {
+        PyErr_SetString(PyExc_IndexError, e.info().c_str());
+        return NULL;
+      }
+    }
     UntypedOpSequence::name_op_v_t gen_name_untyped_op_pairs();
 
     /* --------------------------------------------------------------------- */
 
     // template<class T> typename OpSequence<T>::name_op_v_c_t gen_name_op_pairs() const;
+    %exception {
+      try {
+        $action
+      } catch (PwrNlp::PwrNlpError &e) {
+        PyErr_SetString(PyExc_IndexError, e.info().c_str());
+        return NULL;
+      }
+    }
     template<class T> typename OpSequence<T>::name_op_v_t gen_name_op_pairs();
     %template(gen_name_op_pairs_bool) gen_name_op_pairs<Bool>;
     %template(gen_name_op_pairs_tset) gen_name_op_pairs<TSet>;
@@ -163,6 +245,14 @@ namespace Wccl {
     /* --------------------------------------------------------------------- */
 
     // FunctionalOpSequence::name_op_v_c_t gen_all_op_pairs() const;
+    %exception {
+      try {
+        $action
+      } catch (PwrNlp::PwrNlpError &e) {
+        PyErr_SetString(PyExc_IndexError, e.info().c_str());
+        return NULL;
+      }
+    }
     FunctionalOpSequence::name_op_v_t gen_all_op_pairs();
 
 
@@ -173,7 +263,24 @@ namespace Wccl {
     bool has_lexicon(const std::string& name) const;
     bool has_lexicons() const;
 
+    %exception {
+      try {
+        $action
+      } catch (PwrNlp::PwrNlpError &e) {
+        PyErr_SetString(PyExc_IndexError, e.info().c_str());
+        return NULL;
+      }
+    }
     shared_ptr<const Lexicon> get_lexicon_ptr(const std::string& name) const;
+
+    %exception {
+      try {
+        $action
+      } catch (PwrNlp::PwrNlpError &e) {
+        PyErr_SetString(PyExc_IndexError, e.info().c_str());
+        return NULL;
+      }
+    }
     const Lexicon& get_lexicon(const std::string& name) const;
 
     shared_ptr<const Lexicons> get_lexicons_ptr() const;
-- 
GitLab