From f09fe509986a47691938bb63a82ef6694e3845cf Mon Sep 17 00:00:00 2001 From: Christos Stratopoulos Date: Tue, 10 Dec 2019 14:45:10 -0500 Subject: [PATCH] streamline error handling approaches --- include/continuable/detail/support/asio.hpp | 57 +++++++++------------ 1 file changed, 23 insertions(+), 34 deletions(-) diff --git a/include/continuable/detail/support/asio.hpp b/include/continuable/detail/support/asio.hpp index d7c3fce..04122d4 100644 --- a/include/continuable/detail/support/asio.hpp +++ b/include/continuable/detail/support/asio.hpp @@ -30,23 +30,23 @@ #ifndef CONTINUABLE_DETAIL_ASIO_HPP_INCLUDED #define CONTINUABLE_DETAIL_ASIO_HPP_INCLUDED -#include +#include #if defined(ASIO_STANDALONE) #include #include #include +#if defined(CONTINUABLE_HAS_EXCEPTIONS) +#include +#endif + #if (ASIO_VERSION / 100 % 1000) <= 12 #define CTI_DETAIL_ASIO_HAS_NO_INTEGRATION #elif (ASIO_VERSION / 100 % 1000) <= 14 #define CTI_DETAIL_ASIO_HAS_EXPLICIT_RET_TYPE_INTEGRATION #endif -#if defined(CONTINUABLE_HAS_EXCEPTIONS) -#include -#endif - #define CTI_DETAIL_ASIO_NAMESPACE_BEGIN namespace asio { #define CTI_DETAIL_ASIO_NAMESPACE_END } #else @@ -54,16 +54,16 @@ #include #include +#if defined(CONTINUABLE_HAS_EXCEPTIONS) +#include +#endif + #if (BOOST_VERSION / 100 % 1000) <= 69 #define CTI_DETAIL_ASIO_HAS_NO_INTEGRATION #elif (BOOST_VERSION / 100 % 1000) <= 71 #define CTI_DETAIL_ASIO_HAS_EXPLICIT_RET_TYPE_INTEGRATION #endif -#if defined(CONTINUABLE_HAS_EXCEPTIONS) -#include -#endif - #define CTI_DETAIL_ASIO_NAMESPACE_BEGIN \ namespace boost { \ namespace asio { @@ -79,48 +79,32 @@ "integrated manually with `cti::promisify`." #endif +#include + #include +#if defined(CONTINUABLE_HAS_EXCEPTIONS) +#include +#endif + namespace cti { namespace detail { namespace asio { #if defined(ASIO_STANDALONE) using error_code_t = ::asio::error_code; -using error_cond_t = std::error_condition; #if defined(CONTINUABLE_HAS_EXCEPTIONS) -using exception_t = ::asio::system_error; +using system_error_t = ::asio::system_error; #endif #else using error_code_t = ::boost::system::error_code; -using error_cond_t = ::boost::system::error_condition; #if defined(CONTINUABLE_HAS_EXCEPTIONS) -using exception_t = ::boost::system::system_error; +using system_error_t = ::boost::system::system_error; #endif #endif -#if defined(CONTINUABLE_HAS_EXCEPTIONS) -template -void promise_exception_helper(Promise& promise, error_code_t e) noexcept { - promise.set_exception(std::make_exception_ptr(exception_t(std::move(e)))); -} -#else -template -void promise_exception_helper(Promise& promise, error_code_t e) noexcept - ->decltype(promise.set_exception(std::move(e))) { - return promise.set_exception(std::move(e)); -} - -template -void promise_exception_helper(Promise& promise, error_code_t e) noexcept - ->decltype(promise.set_exception(error_cond_t(e.value(), e.category()))) { - promise.set_exception(error_cond_t(e.value(), e.category())); -} - -#endif - // Binds `promise` to the first argument of a continuable resolver, giving it // the signature of an ASIO handler. template @@ -128,7 +112,12 @@ auto promise_resolver_handler(Promise&& promise) noexcept { return [promise = std::forward(promise)]( error_code_t e, auto&&... args) mutable noexcept { if (e) { - promise_exception_helper(promise, std::move(e)); +#if defined(CONTINUABLE_HAS_EXCEPTIONS) + promise.set_exception( + std::make_exception_ptr(system_error_t(std::move(e)))); +#else + promise.set_exception(cti::exception_t(e.value(), e.category())); +#endif } else { promise.set_value(std::forward(args)...); }