stdexcept 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // -*- C++ -*-
  2. //===--------------------------- stdexcept --------------------------------===//
  3. //
  4. // The LLVM Compiler Infrastructure
  5. //
  6. // This file is dual licensed under the MIT and the University of Illinois Open
  7. // Source Licenses. See LICENSE.TXT for details.
  8. //
  9. //===----------------------------------------------------------------------===//
  10. #ifndef _LIBCPP_STDEXCEPT
  11. #define _LIBCPP_STDEXCEPT
  12. /*
  13. stdexcept synopsis
  14. namespace std
  15. {
  16. class logic_error;
  17. class domain_error;
  18. class invalid_argument;
  19. class length_error;
  20. class out_of_range;
  21. class runtime_error;
  22. class range_error;
  23. class overflow_error;
  24. class underflow_error;
  25. for each class xxx_error:
  26. class xxx_error : public exception // at least indirectly
  27. {
  28. public:
  29. explicit xxx_error(const string& what_arg);
  30. explicit xxx_error(const char* what_arg);
  31. virtual const char* what() const noexcept // returns what_arg
  32. };
  33. } // std
  34. */
  35. #include <__config>
  36. #include <exception>
  37. #include <iosfwd> // for string forward decl
  38. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  39. #pragma GCC system_header
  40. #endif
  41. #ifndef _LIBCPP___REFSTRING
  42. _LIBCPP_BEGIN_NAMESPACE_STD
  43. class _LIBCPP_HIDDEN __libcpp_refstring {
  44. #ifdef __clang__
  45. const char *__imp_ __attribute__((__unused__)); // only clang emits a warning
  46. #else
  47. const char *__imp_;
  48. #endif
  49. };
  50. _LIBCPP_END_NAMESPACE_STD
  51. #endif
  52. namespace std // purposefully not using versioning namespace
  53. {
  54. class _LIBCPP_EXCEPTION_ABI logic_error
  55. : public exception
  56. {
  57. private:
  58. _VSTD::__libcpp_refstring __imp_;
  59. public:
  60. explicit logic_error(const string&);
  61. explicit logic_error(const char*);
  62. logic_error(const logic_error&) _NOEXCEPT;
  63. logic_error& operator=(const logic_error&) _NOEXCEPT;
  64. virtual ~logic_error() _NOEXCEPT;
  65. virtual const char* what() const _NOEXCEPT;
  66. };
  67. class _LIBCPP_EXCEPTION_ABI runtime_error
  68. : public exception
  69. {
  70. private:
  71. _VSTD::__libcpp_refstring __imp_;
  72. public:
  73. explicit runtime_error(const string&);
  74. explicit runtime_error(const char*);
  75. runtime_error(const runtime_error&) _NOEXCEPT;
  76. runtime_error& operator=(const runtime_error&) _NOEXCEPT;
  77. virtual ~runtime_error() _NOEXCEPT;
  78. virtual const char* what() const _NOEXCEPT;
  79. };
  80. class _LIBCPP_EXCEPTION_ABI domain_error
  81. : public logic_error
  82. {
  83. public:
  84. _LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {}
  85. _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s) : logic_error(__s) {}
  86. virtual ~domain_error() _NOEXCEPT;
  87. };
  88. class _LIBCPP_EXCEPTION_ABI invalid_argument
  89. : public logic_error
  90. {
  91. public:
  92. _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const string& __s) : logic_error(__s) {}
  93. _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s) : logic_error(__s) {}
  94. virtual ~invalid_argument() _NOEXCEPT;
  95. };
  96. class _LIBCPP_EXCEPTION_ABI length_error
  97. : public logic_error
  98. {
  99. public:
  100. _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {}
  101. _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s) : logic_error(__s) {}
  102. virtual ~length_error() _NOEXCEPT;
  103. };
  104. class _LIBCPP_EXCEPTION_ABI out_of_range
  105. : public logic_error
  106. {
  107. public:
  108. _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {}
  109. _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s) : logic_error(__s) {}
  110. virtual ~out_of_range() _NOEXCEPT;
  111. };
  112. class _LIBCPP_EXCEPTION_ABI range_error
  113. : public runtime_error
  114. {
  115. public:
  116. _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {}
  117. _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s) : runtime_error(__s) {}
  118. virtual ~range_error() _NOEXCEPT;
  119. };
  120. class _LIBCPP_EXCEPTION_ABI overflow_error
  121. : public runtime_error
  122. {
  123. public:
  124. _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {}
  125. _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s) : runtime_error(__s) {}
  126. virtual ~overflow_error() _NOEXCEPT;
  127. };
  128. class _LIBCPP_EXCEPTION_ABI underflow_error
  129. : public runtime_error
  130. {
  131. public:
  132. _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {}
  133. _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s) : runtime_error(__s) {}
  134. virtual ~underflow_error() _NOEXCEPT;
  135. };
  136. } // std
  137. #endif // _LIBCPP_STDEXCEPT