exceptions.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // Copyright Oliver Kowalke 2013.
  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. // based on boost.thread
  7. #ifndef BOOST_fiber_errorS_H
  8. #define BOOST_fiber_errorS_H
  9. #include <future>
  10. #include <stdexcept>
  11. #include <string>
  12. #include <system_error>
  13. #include <boost/config.hpp>
  14. #include <boost/fiber/detail/config.hpp>
  15. #ifdef BOOST_HAS_ABI_HEADERS
  16. # include BOOST_ABI_PREFIX
  17. #endif
  18. namespace boost {
  19. namespace fibers {
  20. class fiber_error : public std::system_error {
  21. public:
  22. explicit fiber_error( std::error_code ec) :
  23. std::system_error{ ec } {
  24. }
  25. fiber_error( std::error_code ec, const char * what_arg) :
  26. std::system_error{ ec, what_arg } {
  27. }
  28. fiber_error( std::error_code ec, std::string const& what_arg) :
  29. std::system_error{ ec, what_arg } {
  30. }
  31. ~fiber_error() override = default;
  32. };
  33. class lock_error : public fiber_error {
  34. public:
  35. explicit lock_error( std::error_code ec) :
  36. fiber_error{ ec } {
  37. }
  38. lock_error( std::error_code ec, const char * what_arg) :
  39. fiber_error{ ec, what_arg } {
  40. }
  41. lock_error( std::error_code ec, std::string const& what_arg) :
  42. fiber_error{ ec, what_arg } {
  43. }
  44. };
  45. enum class future_errc {
  46. broken_promise = 1,
  47. future_already_retrieved,
  48. promise_already_satisfied,
  49. no_state
  50. };
  51. BOOST_FIBERS_DECL
  52. std::error_category const& future_category() noexcept;
  53. }}
  54. namespace std {
  55. template<>
  56. struct is_error_code_enum< boost::fibers::future_errc > : public true_type {
  57. };
  58. inline
  59. std::error_code make_error_code( boost::fibers::future_errc e) noexcept {
  60. return std::error_code{ static_cast< int >( e), boost::fibers::future_category() };
  61. }
  62. inline
  63. std::error_condition make_error_condition( boost::fibers::future_errc e) noexcept {
  64. return std::error_condition{ static_cast< int >( e), boost::fibers::future_category() };
  65. }
  66. }
  67. namespace boost {
  68. namespace fibers {
  69. class future_error : public fiber_error {
  70. public:
  71. explicit future_error( std::error_code ec) :
  72. fiber_error{ ec } {
  73. }
  74. };
  75. class future_uninitialized : public future_error {
  76. public:
  77. future_uninitialized() :
  78. future_error{ std::make_error_code( future_errc::no_state) } {
  79. }
  80. };
  81. class future_already_retrieved : public future_error {
  82. public:
  83. future_already_retrieved() :
  84. future_error{ std::make_error_code( future_errc::future_already_retrieved) } {
  85. }
  86. };
  87. class broken_promise : public future_error {
  88. public:
  89. broken_promise() :
  90. future_error{ std::make_error_code( future_errc::broken_promise) } {
  91. }
  92. };
  93. class promise_already_satisfied : public future_error {
  94. public:
  95. promise_already_satisfied() :
  96. future_error{ std::make_error_code( future_errc::promise_already_satisfied) } {
  97. }
  98. };
  99. class promise_uninitialized : public future_error {
  100. public:
  101. promise_uninitialized() :
  102. future_error{ std::make_error_code( future_errc::no_state) } {
  103. }
  104. };
  105. class packaged_task_uninitialized : public future_error {
  106. public:
  107. packaged_task_uninitialized() :
  108. future_error{ std::make_error_code( future_errc::no_state) } {
  109. }
  110. };
  111. }}
  112. #ifdef BOOST_HAS_ABI_HEADERS
  113. # include BOOST_ABI_SUFFIX
  114. #endif
  115. #endif // BOOST_fiber_errorS_H