functexcept.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // Function-Based Exception Support -*- C++ -*-
  2. // Copyright (C) 2001-2023 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 bits/functexcept.h
  21. * This is an internal header file, included by other library headers.
  22. * Do not attempt to use it directly. @headername{exception}
  23. *
  24. * This header provides support for -fno-exceptions.
  25. */
  26. //
  27. // ISO C++ 14882: 19.1 Exception classes
  28. //
  29. #ifndef _FUNCTEXCEPT_H
  30. #define _FUNCTEXCEPT_H 1
  31. #include <bits/c++config.h>
  32. #include <bits/exception_defines.h>
  33. namespace std _GLIBCXX_VISIBILITY(default)
  34. {
  35. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  36. #if _GLIBCXX_HOSTED
  37. // Helper for exception objects in <except>
  38. void
  39. __throw_bad_exception(void) __attribute__((__noreturn__));
  40. // Helper for exception objects in <new>
  41. void
  42. __throw_bad_alloc(void) __attribute__((__noreturn__));
  43. void
  44. __throw_bad_array_new_length(void) __attribute__((__noreturn__));
  45. // Helper for exception objects in <typeinfo>
  46. void
  47. __throw_bad_cast(void) __attribute__((__noreturn__));
  48. void
  49. __throw_bad_typeid(void) __attribute__((__noreturn__));
  50. // Helpers for exception objects in <stdexcept>
  51. void
  52. __throw_logic_error(const char*) __attribute__((__noreturn__));
  53. void
  54. __throw_domain_error(const char*) __attribute__((__noreturn__));
  55. void
  56. __throw_invalid_argument(const char*) __attribute__((__noreturn__));
  57. void
  58. __throw_length_error(const char*) __attribute__((__noreturn__));
  59. void
  60. __throw_out_of_range(const char*) __attribute__((__noreturn__));
  61. void
  62. __throw_out_of_range_fmt(const char*, ...) __attribute__((__noreturn__))
  63. __attribute__((__format__(__gnu_printf__, 1, 2)));
  64. void
  65. __throw_runtime_error(const char*) __attribute__((__noreturn__));
  66. void
  67. __throw_range_error(const char*) __attribute__((__noreturn__));
  68. void
  69. __throw_overflow_error(const char*) __attribute__((__noreturn__));
  70. void
  71. __throw_underflow_error(const char*) __attribute__((__noreturn__));
  72. // Helpers for exception objects in <ios>
  73. void
  74. __throw_ios_failure(const char*) __attribute__((__noreturn__));
  75. void
  76. __throw_ios_failure(const char*, int) __attribute__((__noreturn__));
  77. // Helpers for exception objects in <system_error>
  78. void
  79. __throw_system_error(int) __attribute__((__noreturn__));
  80. // Helpers for exception objects in <future>
  81. void
  82. __throw_future_error(int) __attribute__((__noreturn__));
  83. // Helpers for exception objects in <functional>
  84. void
  85. __throw_bad_function_call() __attribute__((__noreturn__));
  86. #else // ! HOSTED
  87. __attribute__((__noreturn__)) inline void
  88. __throw_invalid_argument(const char*)
  89. { std::__terminate(); }
  90. __attribute__((__noreturn__)) inline void
  91. __throw_out_of_range(const char*)
  92. { std::__terminate(); }
  93. __attribute__((__noreturn__)) inline void
  94. __throw_out_of_range_fmt(const char*, ...)
  95. { std::__terminate(); }
  96. __attribute__((__noreturn__)) inline void
  97. __throw_runtime_error(const char*)
  98. { std::__terminate(); }
  99. __attribute__((__noreturn__)) inline void
  100. __throw_overflow_error(const char*)
  101. { std::__terminate(); }
  102. #endif // HOSTED
  103. _GLIBCXX_END_NAMESPACE_VERSION
  104. } // namespace
  105. #endif