translate KeyError too
[mussa.git] / py / stl_container_adapter.cpp
1 #include "stl_container_adapter.hpp"
2
3 #include <boost/python/exception_translator.hpp>
4 using namespace boost::python;
5
6 void translate_index_error(IndexError const& e)
7
8   PyErr_SetString(PyExc_IndexError, "Index out of range"); 
9 }
10
11 void translate_key_error(KeyError const& e)
12
13   PyErr_SetString(PyExc_KeyError, "Key not found"); 
14 }
15
16 void export_container_exceptions() 
17 {
18   boost::python::register_exception_translator<IndexError>(
19     &translate_index_error
20   );
21
22   boost::python::register_exception_translator<KeyError>(
23     &translate_key_error
24   );
25 }