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 | |
9 | #ifndef ERRORS_DWA052500_H_ |
10 | # define ERRORS_DWA052500_H_ |
11 | |
12 | # include <boost/python/detail/prefix.hpp> |
13 | # include <boost/function/function0.hpp> |
14 | |
15 | namespace boost { namespace python { |
16 | |
17 | struct BOOST_PYTHON_DECL_EXCEPTION error_already_set |
18 | { |
19 | virtual ~error_already_set(); |
20 | }; |
21 | |
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>); |
25 | |
26 | template <class T> |
27 | bool handle_exception(T f) |
28 | { |
29 | return handle_exception_impl(function0<void>(boost::ref(f))); |
30 | } |
31 | |
32 | namespace detail { inline void rethrow() { throw; } } |
33 | |
34 | inline void handle_exception() |
35 | { |
36 | handle_exception(f: detail::rethrow); |
37 | } |
38 | |
39 | BOOST_PYTHON_DECL void throw_error_already_set(); |
40 | |
41 | template <class T> |
42 | inline T* expect_non_null(T* x) |
43 | { |
44 | if (x == 0) |
45 | throw_error_already_set(); |
46 | return x; |
47 | } |
48 | |
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); |
52 | |
53 | }} // namespace boost::python |
54 | |
55 | #endif // ERRORS_DWA052500_H_ |
56 | |