errors.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // (C) Copyright David Abrahams 2000.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. //
  6. // The author gratefully acknowleges the support of Dragon Systems, Inc., in
  7. // producing this work.
  8. #ifndef ERRORS_DWA052500_H_
  9. # define ERRORS_DWA052500_H_
  10. # include <boost/python/detail/prefix.hpp>
  11. # include <boost/function/function0.hpp>
  12. namespace boost { namespace python {
  13. struct BOOST_PYTHON_DECL error_already_set
  14. {
  15. virtual ~error_already_set();
  16. };
  17. // Handles exceptions caught just before returning to Python code.
  18. // Returns true iff an exception was caught.
  19. BOOST_PYTHON_DECL bool handle_exception_impl(function0<void>);
  20. template <class T>
  21. bool handle_exception(T f)
  22. {
  23. return handle_exception_impl(function0<void>(boost::ref(f)));
  24. }
  25. namespace detail { inline void rethrow() { throw; } }
  26. inline void handle_exception()
  27. {
  28. handle_exception(detail::rethrow);
  29. }
  30. BOOST_PYTHON_DECL void throw_error_already_set();
  31. template <class T>
  32. inline T* expect_non_null(T* x)
  33. {
  34. if (x == 0)
  35. throw_error_already_set();
  36. return x;
  37. }
  38. // Return source if it is an instance of pytype; throw an appropriate
  39. // exception otherwise.
  40. BOOST_PYTHON_DECL PyObject* pytype_check(PyTypeObject* pytype, PyObject* source);
  41. }} // namespace boost::python
  42. #endif // ERRORS_DWA052500_H_