1 // Copyright David Abrahams 2002.
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 #ifndef TRANSLATE_EXCEPTION_TDS20091020_HPP
6 # define TRANSLATE_EXCEPTION_TDS20091020_HPP
8 # include <boost/python/detail/exception_handler.hpp>
10 # include <boost/call_traits.hpp>
11 # include <boost/type_traits/add_const.hpp>
12 # include <boost/type_traits/add_reference.hpp>
13 # include <boost/type_traits/remove_reference.hpp>
15 # include <boost/function/function0.hpp>
17 namespace boost { namespace python { namespace detail {
19 // A ternary function object used to translate C++ exceptions of type
20 // ExceptionType into Python exceptions by invoking an object of type
21 // Translate. Typically the translate function will be curried with
23 template <class ExceptionType, class Translate>
24 struct translate_exception
26 // workaround for broken gcc that ships with SuSE 9.0 and SuSE 9.1
27 # if defined(__linux__) && defined(__GNUC__) \
28 && BOOST_WORKAROUND(__GNUC__, == 3) \
29 && BOOST_WORKAROUND(__GNUC_MINOR__, == 3) \
30 && (BOOST_WORKAROUND(__GNUC_PATCHLEVEL__, == 1) \
31 || BOOST_WORKAROUND(__GNUC_PATCHLEVEL__, == 3))
32 typedef typename remove_reference<
33 typename add_const<ExceptionType>::type
34 >::type exception_non_ref;
36 typedef typename add_reference<
37 typename add_const<ExceptionType>::type
38 >::type exception_cref;
41 inline bool operator()(
42 exception_handler const& handler
43 , function0<void> const& f
44 , typename call_traits<Translate>::param_type translate) const
50 // workaround for broken gcc that ships with SuSE 9.0 and SuSE 9.1
51 # if defined(__linux__) && defined(__GNUC__) \
52 && BOOST_WORKAROUND(__GNUC__, == 3) \
53 && BOOST_WORKAROUND(__GNUC_MINOR__, == 3) \
54 && (BOOST_WORKAROUND(__GNUC_PATCHLEVEL__, == 1) \
55 || BOOST_WORKAROUND(__GNUC_PATCHLEVEL__, == 3))
56 catch(exception_non_ref& e)
58 catch(exception_cref e)
67 }}} // namespace boost::python::detail
69 #endif // TRANSLATE_EXCEPTION_DWA2002810_HPP