throw_exception.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // detail/throw_exception.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2023 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_THROW_EXCEPTION_HPP
  11. #define ASIO_DETAIL_THROW_EXCEPTION_HPP
  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. #if defined(ASIO_HAS_BOOST_THROW_EXCEPTION)
  17. # include <boost/throw_exception.hpp>
  18. #endif // defined(ASIO_BOOST_THROW_EXCEPTION)
  19. namespace asio {
  20. namespace detail {
  21. #if defined(ASIO_HAS_BOOST_THROW_EXCEPTION)
  22. using boost::throw_exception;
  23. #else // defined(ASIO_HAS_BOOST_THROW_EXCEPTION)
  24. // Declare the throw_exception function for all targets.
  25. template <typename Exception>
  26. void throw_exception(
  27. const Exception& e
  28. ASIO_SOURCE_LOCATION_DEFAULTED_PARAM);
  29. // Only define the throw_exception function when exceptions are enabled.
  30. // Otherwise, it is up to the application to provide a definition of this
  31. // function.
  32. # if !defined(ASIO_NO_EXCEPTIONS)
  33. template <typename Exception>
  34. void throw_exception(
  35. const Exception& e
  36. ASIO_SOURCE_LOCATION_PARAM)
  37. {
  38. throw e;
  39. }
  40. # endif // !defined(ASIO_NO_EXCEPTIONS)
  41. #endif // defined(ASIO_HAS_BOOST_THROW_EXCEPTION)
  42. } // namespace detail
  43. } // namespace asio
  44. #endif // ASIO_DETAIL_THROW_EXCEPTION_HPP