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 7 8 # include <boost/python/detail/exception_handler.hpp> 9 # include <boost/python/detail/type_traits.hpp> 10 11 # include <boost/call_traits.hpp> 12 13 # include <boost/function/function0.hpp> 14 15 namespace boost { namespace python { namespace detail { 16 17 // A ternary function object used to translate C++ exceptions of type 18 // ExceptionType into Python exceptions by invoking an object of type 19 // Translate. Typically the translate function will be curried with 20 // boost::bind(). 21 template <class ExceptionType, class Translate> 22 struct translate_exception 23 { 24 // workaround for broken gcc that ships with SuSE 9.0 and SuSE 9.1 25 # if defined(__linux__) && defined(__GNUC__) \ 26 && BOOST_WORKAROUND(__GNUC__, == 3) \ 27 && BOOST_WORKAROUND(__GNUC_MINOR__, == 3) \ 28 && (BOOST_WORKAROUND(__GNUC_PATCHLEVEL__, == 1) \ 29 || BOOST_WORKAROUND(__GNUC_PATCHLEVEL__, == 3)) 30 typedef typename remove_reference< 31 typename add_const<ExceptionType>::type 32 >::type exception_non_ref; 33 # else 34 typedef typename add_lvalue_reference< 35 typename add_const<ExceptionType>::type 36 >::type exception_cref; 37 # endif 38 operator ()boost::python::detail::translate_exception39 inline bool operator()( 40 exception_handler const& handler 41 , function0<void> const& f 42 , typename call_traits<Translate>::param_type translate) const 43 { 44 try 45 { 46 return handler(f); 47 } 48 // workaround for broken gcc that ships with SuSE 9.0 and SuSE 9.1 49 # if defined(__linux__) && defined(__GNUC__) \ 50 && BOOST_WORKAROUND(__GNUC__, == 3) \ 51 && BOOST_WORKAROUND(__GNUC_MINOR__, == 3) \ 52 && (BOOST_WORKAROUND(__GNUC_PATCHLEVEL__, == 1) \ 53 || BOOST_WORKAROUND(__GNUC_PATCHLEVEL__, == 3)) 54 catch(exception_non_ref& e) 55 # else 56 catch(exception_cref e) 57 # endif 58 { 59 translate(e); 60 return true; 61 } 62 } 63 }; 64 65 }}} // namespace boost::python::detail 66 67 #endif // TRANSLATE_EXCEPTION_DWA2002810_HPP 68