throw_error.ipp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // detail/impl/throw_error.ipp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef ASIO_DETAIL_IMPL_THROW_ERROR_IPP
  11. #define ASIO_DETAIL_IMPL_THROW_ERROR_IPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include "asio/detail/throw_error.hpp"
  17. #include "asio/detail/throw_exception.hpp"
  18. #include "asio/system_error.hpp"
  19. #include "asio/detail/push_options.hpp"
  20. namespace asio {
  21. namespace detail {
  22. void do_throw_error(const asio::error_code& err)
  23. {
  24. asio::system_error e(err);
  25. asio::detail::throw_exception(e);
  26. }
  27. void do_throw_error(const asio::error_code& err, const char* location)
  28. {
  29. // boostify: non-boost code starts here
  30. #if defined(ASIO_MSVC) && defined(ASIO_HAS_STD_SYSTEM_ERROR)
  31. // Microsoft's implementation of std::system_error is non-conformant in that
  32. // it ignores the error code's message when a "what" string is supplied. We'll
  33. // work around this by explicitly formatting the "what" string.
  34. std::string what_msg = location;
  35. what_msg += ": ";
  36. what_msg += err.message();
  37. asio::system_error e(err, what_msg);
  38. asio::detail::throw_exception(e);
  39. #else // defined(ASIO_MSVC) && defined(ASIO_HAS_STD_SYSTEM_ERROR)
  40. // boostify: non-boost code ends here
  41. asio::system_error e(err, location);
  42. asio::detail::throw_exception(e);
  43. // boostify: non-boost code starts here
  44. #endif // defined(ASIO_MSVC) && defined(ASIO_HAS_STD_SYSTEM_ERROR)
  45. // boostify: non-boost code ends here
  46. }
  47. } // namespace detail
  48. } // namespace asio
  49. #include "asio/detail/pop_options.hpp"
  50. #endif // ASIO_DETAIL_IMPL_THROW_ERROR_IPP