translate KeyError too
authorDiane Trout <diane@caltech.edu>
Thu, 30 Aug 2007 22:41:01 +0000 (22:41 +0000)
committerDiane Trout <diane@caltech.edu>
Thu, 30 Aug 2007 22:41:01 +0000 (22:41 +0000)
unfortunately the template register_exception_handler had trouble with
function overloading of the translate functions, so I needed to name
each exception translator differently.

py/module.cpp
py/stl_container_adapter.cpp
py/stl_container_adapter.hpp

index 84564273e81e6862f1865ec22e0cd33675579aa3..f9e6b4fdc339b1d2c5ca0916f234055ba77bc397 100644 (file)
@@ -1,10 +1,10 @@
-#include <boost/python.hpp>
 #include "stl_container_adapter.hpp"
-using namespace boost::python;
+#include <boost/python.hpp>
 
 void export_alphabet();
 void export_annot();
 void export_annotation_colors();
+void export_container_exceptions();
 void export_conserved_path();
 void export_flps();
 void export_glsequence();
@@ -16,8 +16,7 @@ void export_mussa_window();
 
 BOOST_PYTHON_MODULE(mussa)
 {
-  boost::python::register_exception_translator<IndexError>(&translate);
-
+  export_container_exceptions();
   export_alphabet();
   export_annot();
   export_annotation_colors();
index 5135b44288a81255532f30f6d8e66fca17dc1b90..ab1ab36d48a3321dc7f8624e36cfa781b5478483 100644 (file)
@@ -1,12 +1,25 @@
 #include "stl_container_adapter.hpp"
 
-void translate(IndexError const& e)
+#include <boost/python/exception_translator.hpp>
+using namespace boost::python;
+
+void translate_index_error(IndexError const& e)
 { 
   PyErr_SetString(PyExc_IndexError, "Index out of range"); 
 }
 
-void translate(KeyError const& e)
+void translate_key_error(KeyError const& e)
 { 
   PyErr_SetString(PyExc_KeyError, "Key not found"); 
 }
 
+void export_container_exceptions() 
+{
+  boost::python::register_exception_translator<IndexError>(
+    &translate_index_error
+  );
+
+  boost::python::register_exception_translator<KeyError>(
+    &translate_key_error
+  );
+}
index a2989094d234594fb8731f72ec0683f58c737d78..f60c9960583d51a39d453f67f22e33a078666ad6 100644 (file)
 
 struct IndexError : std::exception
 {
-public:
   explicit IndexError(): std::exception() {};
 };
 
-void translate(IndexError const &e);
+void translate_index_error(IndexError const &e);
 
 
 template<typename T>
@@ -75,7 +74,7 @@ public:
   explicit KeyError(): std::exception() {};
 };
 
-void translate(KeyError const &e);
+void translate_key_error(KeyError const &e);
 
 template<typename T>
 struct map_item