Fix up support for ASIO_NO_EXCEPTIONS.

This commit is contained in:
Christopher Kohlhoff 2015-03-17 20:41:14 +11:00
parent df9d70bc55
commit 23b084bb61
3 changed files with 33 additions and 3 deletions

View File

@ -19,6 +19,7 @@
#include <typeinfo>
#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.

View File

@ -17,6 +17,7 @@
#include "asio/detail/config.hpp"
#include <string>
#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<is_same<T, address_v4>::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<is_same<T, address_v6>::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);
}

View File

@ -70,6 +70,23 @@
compile_test<&test>(); \
std::cout << #test << " passed" << std::endl;
#if defined(ASIO_NO_EXCEPTIONS)
namespace asio {
namespace detail {
template <typename T>
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 <boost/test/unit_test.hpp>