bad_address_cast.hpp 1.5 KB

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