From 23b084bb617f91ab0bbeddc796cf72d98663f236 Mon Sep 17 00:00:00 2001 From: Christopher Kohlhoff Date: Tue, 17 Mar 2015 20:41:14 +1100 Subject: [PATCH] Fix up support for ASIO_NO_EXCEPTIONS. --- asio/include/asio/executor.hpp | 8 +++++++- asio/include/asio/ip/address.hpp | 11 +++++++++-- asio/src/tests/unit/unit_test.hpp | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/asio/include/asio/executor.hpp b/asio/include/asio/executor.hpp index 66886da3..1810d93b 100644 --- a/asio/include/asio/executor.hpp +++ b/asio/include/asio/executor.hpp @@ -19,6 +19,7 @@ #include #include "asio/detail/cstddef.hpp" #include "asio/detail/memory.hpp" +#include "asio/detail/throw_exception.hpp" #include "asio/execution_context.hpp" #include "asio/is_executor.hpp" @@ -302,7 +303,12 @@ private: // Helper function to check and return the implementation pointer. impl_base* get_impl() { - return impl_ ? impl_ : throw bad_executor(); + if (!impl_) + { + bad_executor ex; + asio::detail::throw_exception(ex); + } + return impl_; } // Helper function to clone another implementation. diff --git a/asio/include/asio/ip/address.hpp b/asio/include/asio/ip/address.hpp index ad20c458..d8068ba9 100644 --- a/asio/include/asio/ip/address.hpp +++ b/asio/include/asio/ip/address.hpp @@ -17,6 +17,7 @@ #include "asio/detail/config.hpp" #include +#include "asio/detail/throw_exception.hpp" #include "asio/detail/type_traits.hpp" #include "asio/error_code.hpp" #include "asio/ip/address_v4.hpp" @@ -242,7 +243,10 @@ inline T address_cast(const address& addr, typename enable_if::value>::type* = 0) { if (!addr.is_v4()) - throw bad_address_cast(); + { + bad_address_cast ex; + asio::detail::throw_exception(ex); + } return get_v4_helper(addr); } @@ -255,7 +259,10 @@ inline T address_cast(const address& addr, typename enable_if::value>::type* = 0) { if (!addr.is_v6()) - throw bad_address_cast(); + { + bad_address_cast ex; + asio::detail::throw_exception(ex); + } return get_v6_helper(addr); } diff --git a/asio/src/tests/unit/unit_test.hpp b/asio/src/tests/unit/unit_test.hpp index 1687c7c4..9925bc07 100644 --- a/asio/src/tests/unit/unit_test.hpp +++ b/asio/src/tests/unit/unit_test.hpp @@ -70,6 +70,23 @@ compile_test<&test>(); \ std::cout << #test << " passed" << std::endl; +#if defined(ASIO_NO_EXCEPTIONS) + +namespace asio { +namespace detail { + +template +void throw_exception(const T& t) +{ + std::cout << "Exception: " << t.what() << std::endl; + std::abort(); +} + +} // namespace detail +} // namespace asio + +#endif // defined(ASIO_NO_EXCEPTIONS) + #else // defined(ASIO_STANDALONE) #include