translate KeyError too
[mussa.git] / py / stl_container_adapter.cpp
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
+  );
+}