sl@0: // (C) Copyright David Abrahams 2000. sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: // sl@0: // The author gratefully acknowleges the support of Dragon Systems, Inc., in sl@0: // producing this work. sl@0: sl@0: #ifndef ERRORS_DWA052500_H_ sl@0: # define ERRORS_DWA052500_H_ sl@0: sl@0: # include sl@0: # include sl@0: sl@0: namespace boost { namespace python { sl@0: sl@0: struct BOOST_PYTHON_DECL_EXCEPTION error_already_set sl@0: { sl@0: virtual ~error_already_set(); sl@0: }; sl@0: sl@0: // Handles exceptions caught just before returning to Python code. sl@0: // Returns true iff an exception was caught. sl@0: BOOST_PYTHON_DECL bool handle_exception_impl(function0); sl@0: sl@0: template sl@0: bool handle_exception(T f) sl@0: { sl@0: return handle_exception_impl(function0(boost::ref(f))); sl@0: } sl@0: sl@0: namespace detail { inline void rethrow() { throw; } } sl@0: sl@0: inline void handle_exception() sl@0: { sl@0: handle_exception(detail::rethrow); sl@0: } sl@0: sl@0: BOOST_PYTHON_DECL void throw_error_already_set(); sl@0: sl@0: template sl@0: inline T* expect_non_null(T* x) sl@0: { sl@0: if (x == 0) sl@0: throw_error_already_set(); sl@0: return x; sl@0: } sl@0: sl@0: // Return source if it is an instance of pytype; throw an appropriate sl@0: // exception otherwise. sl@0: BOOST_PYTHON_DECL PyObject* pytype_check(PyTypeObject* pytype, PyObject* source); sl@0: sl@0: }} // namespace boost::python sl@0: sl@0: #endif // ERRORS_DWA052500_H_