1 2 // Copyright Oliver Kowalke 2009. 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 7 #ifndef BOOST_COROUTINES_EXCEPTIONS_H 8 #define BOOST_COROUTINES_EXCEPTIONS_H 9 10 #include <stdexcept> 11 #include <string> 12 13 #include <boost/config.hpp> 14 #include <boost/detail/scoped_enum_emulation.hpp> 15 #include <boost/system/error_code.hpp> 16 #include <boost/system/system_error.hpp> 17 #include <boost/type_traits/integral_constant.hpp> 18 19 #include <boost/coroutine/detail/config.hpp> 20 21 #ifdef BOOST_HAS_ABI_HEADERS 22 # include BOOST_ABI_PREFIX 23 #endif 24 25 namespace boost { 26 namespace coroutines { 27 namespace detail { 28 29 struct forced_unwind {}; 30 31 } 32 BOOST_SCOPED_ENUM_DECLARE_BEGIN(coroutine_errc)33BOOST_SCOPED_ENUM_DECLARE_BEGIN(coroutine_errc) 34 { 35 no_data = 1 36 } 37 BOOST_SCOPED_ENUM_DECLARE_END(coroutine_errc) 38 39 BOOST_COROUTINES_DECL 40 system::error_category const& coroutine_category() BOOST_NOEXCEPT; 41 42 } 43 44 namespace system { 45 46 template<> 47 struct is_error_code_enum< coroutines::coroutine_errc > : public true_type 48 {}; 49 50 #ifdef BOOST_NO_CXX11_SCOPED_ENUMS 51 template<> 52 struct is_error_code_enum< coroutines::coroutine_errc::enum_type > : public true_type 53 {}; 54 #endif 55 56 inline make_error_code(coroutines::coroutine_errc e)57error_code make_error_code( coroutines::coroutine_errc e) //BOOST_NOEXCEPT 58 { 59 return error_code( underlying_cast< int >( e), coroutines::coroutine_category() ); 60 } 61 62 inline make_error_condition(coroutines::coroutine_errc e)63error_condition make_error_condition( coroutines::coroutine_errc e) //BOOST_NOEXCEPT 64 { 65 return error_condition( underlying_cast< int >( e), coroutines::coroutine_category() ); 66 } 67 68 } 69 70 namespace coroutines { 71 72 class coroutine_error : public std::logic_error 73 { 74 private: 75 system::error_code ec_; 76 77 public: coroutine_error(system::error_code ec)78 coroutine_error( system::error_code ec) : 79 logic_error( ec.message() ), 80 ec_( ec) 81 {} 82 code() const83 system::error_code const& code() const BOOST_NOEXCEPT 84 { return ec_; } 85 }; 86 87 class invalid_result : public coroutine_error 88 { 89 public: invalid_result()90 invalid_result() : 91 coroutine_error( 92 system::make_error_code( 93 coroutine_errc::no_data) ) 94 {} 95 }; 96 97 }} 98 99 #ifdef BOOST_HAS_ABI_HEADERS 100 # include BOOST_ABI_SUFFIX 101 #endif 102 103 #endif // BOOST_COROUTINES_EXCEPTIONS_H 104