exceptions.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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/detail/scoped_enum_emulation.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 system::error_category const& coroutine_category() BOOST_NOEXCEPT;
  29. }
  30. namespace system {
  31. template<>
  32. struct is_error_code_enum< coroutines::coroutine_errc > : public true_type
  33. {};
  34. #ifdef BOOST_NO_CXX11_SCOPED_ENUMS
  35. template<>
  36. struct is_error_code_enum< coroutines::coroutine_errc::enum_type > : public true_type
  37. {};
  38. #endif
  39. inline
  40. error_code make_error_code( coroutines::coroutine_errc e) //BOOST_NOEXCEPT
  41. {
  42. return error_code( underlying_cast< int >( e), coroutines::coroutine_category() );
  43. }
  44. inline
  45. error_condition make_error_condition( coroutines::coroutine_errc e) //BOOST_NOEXCEPT
  46. {
  47. return error_condition( underlying_cast< int >( e), coroutines::coroutine_category() );
  48. }
  49. }
  50. namespace coroutines {
  51. class coroutine_error : public std::logic_error
  52. {
  53. private:
  54. system::error_code ec_;
  55. public:
  56. coroutine_error( system::error_code ec) :
  57. logic_error( ec.message() ),
  58. ec_( ec)
  59. {}
  60. system::error_code const& code() const BOOST_NOEXCEPT
  61. { return ec_; }
  62. const char* what() const throw()
  63. { return code().message().c_str(); }
  64. };
  65. class invalid_result : public coroutine_error
  66. {
  67. public:
  68. invalid_result() :
  69. coroutine_error(
  70. system::make_error_code(
  71. coroutine_errc::no_data) )
  72. {}
  73. };
  74. }}
  75. #ifdef BOOST_HAS_ABI_HEADERS
  76. # include BOOST_ABI_SUFFIX
  77. #endif
  78. #endif // BOOST_COROUTINES_EXCEPTIONS_H