fix doc example typo
[boost.git] / boost / python / errors.hpp
blob72960d9ea2cd80f15d991aeb2f0076a3665007ae
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.
9 #ifndef ERRORS_DWA052500_H_
10 # define ERRORS_DWA052500_H_
12 # include <boost/python/detail/prefix.hpp>
13 # include <boost/function/function0.hpp>
15 namespace boost { namespace python {
17 struct BOOST_PYTHON_DECL_EXCEPTION error_already_set
19 virtual ~error_already_set();
22 // Handles exceptions caught just before returning to Python code.
23 // Returns true iff an exception was caught.
24 BOOST_PYTHON_DECL bool handle_exception_impl(function0<void>);
26 template <class T>
27 bool handle_exception(T f)
29 return handle_exception_impl(function0<void>(boost::ref(f)));
32 namespace detail { inline void rethrow() { throw; } }
34 inline void handle_exception()
36 handle_exception(detail::rethrow);
39 BOOST_PYTHON_DECL void throw_error_already_set();
41 template <class T>
42 inline T* expect_non_null(T* x)
44 if (x == 0)
45 throw_error_already_set();
46 return x;
49 // Return source if it is an instance of pytype; throw an appropriate
50 // exception otherwise.
51 BOOST_PYTHON_DECL PyObject* pytype_check(PyTypeObject* pytype, PyObject* source);
53 }} // namespace boost::python
55 #endif // ERRORS_DWA052500_H_