Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
2.8KB

  1. //
  2. // system_error.hpp
  3. // ~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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_SYSTEM_ERROR_HPP
  11. #define ASIO_SYSTEM_ERROR_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_STD_SYSTEM_ERROR)
  17. # include <system_error>
  18. #else // defined(ASIO_HAS_STD_SYSTEM_ERROR)
  19. # include <cerrno>
  20. # include <exception>
  21. # include <string>
  22. # include "asio/error_code.hpp"
  23. # include "asio/detail/scoped_ptr.hpp"
  24. #endif // defined(ASIO_HAS_STD_SYSTEM_ERROR)
  25. #include "asio/detail/push_options.hpp"
  26. namespace asio {
  27. #if defined(ASIO_HAS_STD_SYSTEM_ERROR)
  28. typedef std::system_error system_error;
  29. #else // defined(ASIO_HAS_STD_SYSTEM_ERROR)
  30. /// The system_error class is used to represent system conditions that
  31. /// prevent the library from operating correctly.
  32. class system_error
  33. : public std::exception
  34. {
  35. public:
  36. /// Construct with an error code.
  37. system_error(const error_code& ec)
  38. : code_(ec),
  39. context_()
  40. {
  41. }
  42. /// Construct with an error code and context.
  43. system_error(const error_code& ec, const std::string& context)
  44. : code_(ec),
  45. context_(context)
  46. {
  47. }
  48. /// Copy constructor.
  49. system_error(const system_error& other)
  50. : std::exception(other),
  51. code_(other.code_),
  52. context_(other.context_),
  53. what_()
  54. {
  55. }
  56. /// Destructor.
  57. virtual ~system_error() throw ()
  58. {
  59. }
  60. /// Assignment operator.
  61. system_error& operator=(const system_error& e)
  62. {
  63. context_ = e.context_;
  64. code_ = e.code_;
  65. what_.reset();
  66. return *this;
  67. }
  68. /// Get a string representation of the exception.
  69. virtual const char* what() const throw ()
  70. {
  71. #if !defined(ASIO_NO_EXCEPTIONS)
  72. try
  73. #endif // !defined(ASIO_NO_EXCEPTIONS)
  74. {
  75. if (!what_.get())
  76. {
  77. std::string tmp(context_);
  78. if (tmp.length())
  79. tmp += ": ";
  80. tmp += code_.message();
  81. what_.reset(new std::string(tmp));
  82. }
  83. return what_->c_str();
  84. }
  85. #if !defined(ASIO_NO_EXCEPTIONS)
  86. catch (std::exception&)
  87. {
  88. return "system_error";
  89. }
  90. #endif // !defined(ASIO_NO_EXCEPTIONS)
  91. }
  92. /// Get the error code associated with the exception.
  93. error_code code() const
  94. {
  95. return code_;
  96. }
  97. private:
  98. // The code associated with the error.
  99. error_code code_;
  100. // The context associated with the error.
  101. std::string context_;
  102. // The string representation of the error.
  103. mutable asio::detail::scoped_ptr<std::string> what_;
  104. };
  105. #endif // defined(ASIO_HAS_STD_SYSTEM_ERROR)
  106. } // namespace asio
  107. #include "asio/detail/pop_options.hpp"
  108. #endif // ASIO_SYSTEM_ERROR_HPP