stdexcept 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // Standard exception classes -*- C++ -*-
  2. // Copyright (C) 2001, 2002, 2005, 2007, 2009 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file stdexcept
  21. * This is a Standard C++ Library header.
  22. */
  23. //
  24. // ISO C++ 19.1 Exception classes
  25. //
  26. #ifndef _GLIBCXX_STDEXCEPT
  27. #define _GLIBCXX_STDEXCEPT 1
  28. #pragma GCC system_header
  29. #include <exception>
  30. #include <string>
  31. _GLIBCXX_BEGIN_NAMESPACE(std)
  32. /**
  33. * @addtogroup exceptions
  34. * @{
  35. */
  36. /** Logic errors represent problems in the internal logic of a program;
  37. * in theory, these are preventable, and even detectable before the
  38. * program runs (e.g., violations of class invariants).
  39. * @brief One of two subclasses of exception.
  40. */
  41. class logic_error : public exception
  42. {
  43. string _M_msg;
  44. public:
  45. /** Takes a character string describing the error. */
  46. explicit
  47. logic_error(const string& __arg);
  48. virtual
  49. ~logic_error() throw();
  50. /** Returns a C-style character string describing the general cause of
  51. * the current error (the same string passed to the ctor). */
  52. virtual const char*
  53. what() const throw();
  54. };
  55. /** Thrown by the library, or by you, to report domain errors (domain in
  56. * the mathematical sense). */
  57. class domain_error : public logic_error
  58. {
  59. public:
  60. explicit domain_error(const string& __arg);
  61. };
  62. /** Thrown to report invalid arguments to functions. */
  63. class invalid_argument : public logic_error
  64. {
  65. public:
  66. explicit invalid_argument(const string& __arg);
  67. };
  68. /** Thrown when an object is constructed that would exceed its maximum
  69. * permitted size (e.g., a basic_string instance). */
  70. class length_error : public logic_error
  71. {
  72. public:
  73. explicit length_error(const string& __arg);
  74. };
  75. /** This represents an argument whose value is not within the expected
  76. * range (e.g., boundary checks in basic_string). */
  77. class out_of_range : public logic_error
  78. {
  79. public:
  80. explicit out_of_range(const string& __arg);
  81. };
  82. /** Runtime errors represent problems outside the scope of a program;
  83. * they cannot be easily predicted and can generally only be caught as
  84. * the program executes.
  85. * @brief One of two subclasses of exception.
  86. */
  87. class runtime_error : public exception
  88. {
  89. string _M_msg;
  90. public:
  91. /** Takes a character string describing the error. */
  92. explicit
  93. runtime_error(const string& __arg);
  94. virtual
  95. ~runtime_error() throw();
  96. /** Returns a C-style character string describing the general cause of
  97. * the current error (the same string passed to the ctor). */
  98. virtual const char*
  99. what() const throw();
  100. };
  101. /** Thrown to indicate range errors in internal computations. */
  102. class range_error : public runtime_error
  103. {
  104. public:
  105. explicit range_error(const string& __arg);
  106. };
  107. /** Thrown to indicate arithmetic overflow. */
  108. class overflow_error : public runtime_error
  109. {
  110. public:
  111. explicit overflow_error(const string& __arg);
  112. };
  113. /** Thrown to indicate arithmetic underflow. */
  114. class underflow_error : public runtime_error
  115. {
  116. public:
  117. explicit underflow_error(const string& __arg);
  118. };
  119. // @} group exceptions
  120. _GLIBCXX_END_NAMESPACE
  121. #endif /* _GLIBCXX_STDEXCEPT */