exception_translator.cpp 640 B

12345678910111213141516171819202122232425262728
  1. // Copyright David Abrahams 2004. Distributed under the Boost
  2. // Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #include <boost/python/module.hpp>
  5. #include <boost/python/def.hpp>
  6. #include <boost/python/exception_translator.hpp>
  7. struct error {};
  8. void translate(error const& /*e*/)
  9. {
  10. PyErr_SetString(PyExc_RuntimeError, "!!!error!!!");
  11. }
  12. void throw_error()
  13. {
  14. throw error();
  15. }
  16. BOOST_PYTHON_MODULE(exception_translator_ext)
  17. {
  18. using namespace boost::python;
  19. register_exception_translator<error>(&translate);
  20. def("throw_error", throw_error);
  21. }