exceptions.hpp 2.1 KB

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