exception 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP_EXCEPTION
  10. #define _LIBCPP_EXCEPTION
  11. /*
  12. exception synopsis
  13. namespace std
  14. {
  15. class exception
  16. {
  17. public:
  18. exception() noexcept;
  19. exception(const exception&) noexcept;
  20. exception& operator=(const exception&) noexcept;
  21. virtual ~exception() noexcept;
  22. virtual const char* what() const noexcept;
  23. };
  24. class bad_exception
  25. : public exception
  26. {
  27. public:
  28. bad_exception() noexcept;
  29. bad_exception(const bad_exception&) noexcept;
  30. bad_exception& operator=(const bad_exception&) noexcept;
  31. virtual ~bad_exception() noexcept;
  32. virtual const char* what() const noexcept;
  33. };
  34. typedef void (*unexpected_handler)();
  35. unexpected_handler set_unexpected(unexpected_handler f ) noexcept;
  36. unexpected_handler get_unexpected() noexcept;
  37. [[noreturn]] void unexpected();
  38. typedef void (*terminate_handler)();
  39. terminate_handler set_terminate(terminate_handler f ) noexcept;
  40. terminate_handler get_terminate() noexcept;
  41. [[noreturn]] void terminate() noexcept;
  42. bool uncaught_exception() noexcept;
  43. int uncaught_exceptions() noexcept; // C++17
  44. typedef unspecified exception_ptr;
  45. exception_ptr current_exception() noexcept;
  46. void rethrow_exception [[noreturn]] (exception_ptr p);
  47. template<class E> exception_ptr make_exception_ptr(E e) noexcept;
  48. class nested_exception
  49. {
  50. public:
  51. nested_exception() noexcept;
  52. nested_exception(const nested_exception&) noexcept = default;
  53. nested_exception& operator=(const nested_exception&) noexcept = default;
  54. virtual ~nested_exception() = default;
  55. // access functions
  56. [[noreturn]] void rethrow_nested() const;
  57. exception_ptr nested_ptr() const noexcept;
  58. };
  59. template <class T> [[noreturn]] void throw_with_nested(T&& t);
  60. template <class E> void rethrow_if_nested(const E& e);
  61. } // std
  62. */
  63. #include <__assert> // all public C++ headers provide the assertion handler
  64. #include <__config>
  65. #include <__exception/exception.h>
  66. #include <__exception/exception_ptr.h>
  67. #include <__exception/nested_exception.h>
  68. #include <__exception/operations.h>
  69. #include <__exception/terminate.h>
  70. #include <version>
  71. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  72. # pragma GCC system_header
  73. #endif
  74. #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
  75. # include <cstdlib>
  76. # include <type_traits>
  77. #endif
  78. #endif // _LIBCPP_EXCEPTION