bad_address_cast.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // ip/bad_address_cast.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 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 BOOST_ASIO_IP_BAD_ADDRESS_CAST_HPP
  11. #define BOOST_ASIO_IP_BAD_ADDRESS_CAST_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <typeinfo>
  17. #include <boost/asio/detail/push_options.hpp>
  18. namespace boost {
  19. namespace asio {
  20. namespace ip {
  21. /// Thrown to indicate a failed address conversion.
  22. class bad_address_cast :
  23. #if defined(BOOST_ASIO_MSVC) && defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS
  24. public std::exception
  25. #else
  26. public std::bad_cast
  27. #endif
  28. {
  29. public:
  30. /// Default constructor.
  31. bad_address_cast() {}
  32. /// Copy constructor.
  33. bad_address_cast(const bad_address_cast& other) noexcept
  34. #if defined(BOOST_ASIO_MSVC) && defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS
  35. : std::exception(static_cast<const std::exception&>(other))
  36. #else
  37. : std::bad_cast(static_cast<const std::bad_cast&>(other))
  38. #endif
  39. {
  40. }
  41. /// Destructor.
  42. virtual ~bad_address_cast() noexcept {}
  43. /// Get the message associated with the exception.
  44. virtual const char* what() const noexcept
  45. {
  46. return "bad address cast";
  47. }
  48. };
  49. } // namespace ip
  50. } // namespace asio
  51. } // namespace boost
  52. #include <boost/asio/detail/pop_options.hpp>
  53. #endif // BOOST_ASIO_IP_ADDRESS_HPP